Update Computer Description

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 5 years and 2 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Computer Description

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Computer Description

Post by jvierra »

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.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Update Computer Description

Post by mxtrinidad »

Hey JVierra!! I always learn things from you. Thank You!
PowerShell is Awesome!!

:)
TSMike777
Posts: 5
Last visit: Wed Mar 20, 2024 1:17 pm

Re: Update Computer Description

Post by TSMike777 »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Computer Description

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update Computer Description

Post by jvierra »

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.
I didn't take it that way. I just wanted to let you know that the code and method are well tested.

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.
This topic is 5 years and 2 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked