Link to home
Start Free TrialLog in
Avatar of jacksonwsa
jacksonwsa

asked on

Adding information to description field of computer objects in Active Directory

Hello,

I'm looking for a script that will add information to the description field for a list of servers. If it would work with a servers.txt file that I could put a list of server in that would be ideal or something along those lines. I'm looking to add "Virtual" to our "Servers" OU in the description field to like 800 servers so that we can query against that to find all of our vm's. Thanks!
Avatar of Kent Dyer
Kent Dyer
Flag of United States of America image

First, I would start with the ADSI Script-o-matic from Microsoft..

http://technet.microsoft.com/en-us/scriptcenter/dd939958.aspx

This should help you get started..

HTH,

Kent
Do you want powershell, vbs or batch file?
Here is something to start with, I use it as a user login script. .VBS
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

' get service tag and computer manufacturer
For Each objSMBIOS in objWMI.ExecQuery("Select * from Win32_SystemEnclosure")
serviceTag = replace(objSMBIOS.SerialNumber, ",", ".")
manufacturer = replace(objSMBIOS.Manufacturer, ",", ".")
Next

' get computer model
For Each objComputer in objWMI.ExecQuery("Select * from Win32_ComputerSystem")
model = trim(replace(objComputer.Model, ",", "."))
Next

' get computer object in AD
Set objSysInfo = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)

' build up description field data and save into computer object
objComputer.Description = WshNetwork.UserName & " - Computer Manufacturer: " & manufacturer & " - Model: " & model & " - Serial Number: " & " " & serviceTag & " " & Now 
objComputer.SetInfo

Open in new window

Avatar of jacksonwsa
jacksonwsa

ASKER

Powershell preferably but anything would work. I just need something simple if possible.
What about this. I found this online and would only need to change it to work against computer objects rather than a user, and a .txt file with a list of servers (get-content) in some form or fashion..

Import-Module ActiveDirectory
 $users = $i = $null
 $users = Get-ADUser -SearchBase "ou=testou,dc=nwtraders,dc=com" -filter * `
  -property description
 ForEach($user in $users)
  {
   if([string]::isNullOrEmpty($user.description))
    {
      "modifying $($user.name)"
      Set-ADUser -Identity $user.distinguishedName -Description "added via script"
      $i++
    }
 }
"modified $i users"
ASKER CERTIFIED SOLUTION
Avatar of jacksonwsa
jacksonwsa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not resolved