Update Computer Description

Ask your Windows 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.
jvierra
Posts: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Update Computer Description

Post by jvierra » Tue Mar 12, 2019 8:37 am

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: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Update Computer Description

Post by jvierra » Tue Mar 12, 2019 9:30 am

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
Site Admin
Posts: 368
Joined: Sun Mar 03, 2013 12:42 pm

Re: Update Computer Description

Post by mxtrinidad » Tue Mar 12, 2019 9:59 am

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

:)

TSMike
Posts: 4
Joined: Fri Feb 15, 2019 1:55 pm

Re: Update Computer Description

Post by TSMike » 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.

jvierra
Posts: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Update Computer Description

Post by jvierra » Tue Mar 12, 2019 10:24 am

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: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Update Computer Description

Post by jvierra » Tue Mar 12, 2019 10:56 am

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.

Locked