Max - the issue is not that simple. Under the SC agent we would not want to load the ad module. Second "[adsi}" is a Net object. Third MS uses the COM object for all things to gain ad info and has not added a Net object that does the same thing. Hopefully they will soon.
COM/COM+ is still a current tech ology and we can create COM visible objects with the Net Framework. COM will be used for quite some time.
The issue is not COM. I suspect something in the execution environment when executing under the SC agent.
We can eliminate the COM call by using the searcher to retrieve the computer object:
$c = ([adsisearcher]"(samaccountname=$($env:computername)$)").FindOne().GetDirectoryEntry()
$c.description
This might work better under the SC agent.
Update Computer Description
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Update Computer Description
I forgot to thank Max for the reminder that when only needing the computer object that "[adsisearcher]" is much easier to use and requires not outside functions or objects.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Update Computer Description
Hey JVierra!! I always learn things from you. Thank You!
PowerShell is Awesome!!
PowerShell is Awesome!!
Re: Update Computer Description
Sorry jvierra, I do believe that the code you have provided has been solid and it is very much appreciated. I didn't mean to infer otherwise and I truly appreciate the help you have provided to me.
That being said, I did try your latest adsisearcher code. When I ran this:
$c = ([adsisearcher]"(samaccountname=$($env:computername)$)").FindOne().GetDirectoryEntry()
I got this:
You cannot call a method on a null-valued expression.
I even tried hard-coding the computer name into the searcher (with the trailing "$") and received the same message.
I too believe that all this code is sound and should be working. This leads me to believe that my issue does lie within our AD environment. If this is truly an issue with our internal AD, I don't want to take up any more of your time chasing a ghost. If you have any other ideas, I am open to them. If you wish to close this post stating the issue is internal, I will be satisfied with that as well.
That being said, I did try your latest adsisearcher code. When I ran this:
$c = ([adsisearcher]"(samaccountname=$($env:computername)$)").FindOne().GetDirectoryEntry()
I got this:
You cannot call a method on a null-valued expression.
I even tried hard-coding the computer name into the searcher (with the trailing "$") and received the same message.
I too believe that all this code is sound and should be working. This leads me to believe that my issue does lie within our AD environment. If this is truly an issue with our internal AD, I don't want to take up any more of your time chasing a ghost. If you have any other ideas, I am open to them. If you wish to close this post stating the issue is internal, I will be satisfied with that as well.
Re: Update Computer Description
RIght on. It impressed the hell out of me when I first saw Monad. I try to share as much as I can t get basic techs excited enough to dive under the covers.
User groups are the best way to go for new users. The sharing can bootstrap a good experience. We need more user groups.
User groups are the best way to go for new users. The sharing can bootstrap a good experience. We need more user groups.
Re: Update Computer Description
I didn't take it that way. I just wanted to let you know that the code and method are well tested.TSMike wrote: ↑Tue Mar 12, 2019 10:08 am Sorry jvierra, I do believe that the code you have provided has been solid and it is very much appreciated. I didn't mean to infer otherwise and I truly appreciate the help you have provided to me.
That being said, I did try your latest adsisearcher code. When I ran this:
$c = ([adsisearcher]"(samaccountname=$($env:computername)$)").FindOne().GetDirectoryEntry()
I got this:
You cannot call a method on a null-valued expression.
I even tried hard-coding the computer name into the searcher (with the trailing "$") and received the same message.
I too believe that all this code is sound and should be working. This leads me to believe that my issue does lie within our AD environment. If this is truly an issue with our internal AD, I don't want to take up any more of your time chasing a ghost. If you have any other ideas, I am open to them. If you wish to close this post stating the issue is internal, I will be satisfied with that as well.
If the last code I posted fails then you have other issues. If you are running under the system account under the SM agent then the profile and the environment may not be loaded or may not have been loaded when the code executes. You can tune this in SCCM. The step needs to run after the network is available at a minimum.