Populating Active Directory with Computer Information

metroHere is a very quick tip i have employed to good effect at client sites.

It goes back to this very cool command i shared a few years ago now, here.

Being able to quickly identify a service tag, or even the model of a PC is very useful (At least to me) to determine if a hardware fault can be covered by a warranty repair, and with normal wear and tear stickers on machines can become difficult to read or be missing altogether!

So what is the answer i have used? Just add the info to the computers description field in AD.

Adjusting the above command slightly for use in PowerShell we are left with this..

Get-WMIObject  Win32_ComputerSystemProduct | Select Vendor, Name, IdentifyingNumber

Which gives us the following output.

WMI Info

If we just want a single value, for example just the IdentifyingNumber, we just enclose the query in brackets, and select our value with a period and the value name, like this,

(Get-WMIObject Win32_ComputerSystemProduct).IdentifyingNumber

WMI Info 2

Excellent, but we do not want to visit each PC and note it down and then enter it into AD do we?

No we do not.

So firstly what we can do is load up the ActiveDirectory Management Tools for PowerShell.

Import-Module ActiveDirectory

ImportModule ActiveDirectory

Next we can set  target computer.

$computer = "Rob-WIN8"

Computer Variable

Now create some variables, to collect our system information.

(adding in “–ComputerName $computer”  to direct out query to the right computer)

$vendor = (Get-WMIObject -ComputerName $computer  Win32_ComputerSystemProduct).Vendor
$name = (Get-WMIObject -ComputerName $computer  Win32_ComputerSystemProduct).Name
$identifyingNumber = (Get-WMIObject -ComputerName $computer  Win32_ComputerSystemProduct).identifyingNumber


Now, if we execute this series of commands, the values returned are stored inside the relevant variable.

So if i just add in those variables below, it will output the value.

Output Variables


What is important to realise here, is now those values are stored, we can use them elsewhere

So, running this command,

Set-ADComputer $computer –Description “$vendor : $name : $identifyingNumber”

Has the following effect..


Now, currently of course, the only computer we have selected is the one we manually entered in $computer.

If we change the script now slightly,

$computers = Get-ADComputer -Filter * -searchBase "OU=Computers,DC=mydomain,DC=local"


Will collect all computers in the ‘Computers’ OU

if we then enclose all of the remaining queries inside a foreach statement,

foreach ($computer in $computers)
$vendor = (Get-WMIObject -ComputerName $computer  Win32_ComputerSystemProduct).Vendor
$name = (Get-WMIObject -ComputerName $computer  Win32_ComputerSystemProduct).Name
$identifyingNumber = (Get-WMIObject -ComputerName $computer  Win32_ComputerSystemProduct).IdentifyingNumber

# Show Output of Variable

    Set-ADComputer $computer –Description “$vendor : $name : $identifyingNumber”


When we execute the script, each computer identified will be queried in turn* and you will see your AD populated with the info above.

* assuming it is on and there is nothing blocking a WMI query across the network.


About Robert Pearman
Robert Pearman is a UK based Small Business Server enthusiast. He has been working within the SMB IT Industry for what feels like forever. Robert likes Piña colada and taking walks in the rain, on occasion he also enjoys writing about Small Business Technology like Windows Server Essentials or more recently writing PowerShell Scripts. If you're in trouble, and you can find him, maybe you can ask him a question.

Leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: