[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Add info to description in AD from list

Hello Experts!!!

I have a .csv of (Column A) Computer Names and (Column B) Serial Numbers saved on my hard drive.  (Can also use txt)

My task is to update the description for each Computer Account in Active Directory with its corresponding Serial Number.

I would like a script (PS, bat, VBscript, etc) to add the Serial Number from Column B to the current description of the corresponding Computer Name in Column A in Active Directory.  (I do not want to clear out any current description.  If there is a description, I would simply like to add the SN to the end.)


Any assistance is appreciated.




------------------------------------------------------------
Not Completely Relevant Information Below:
------------------------------------------------------------
My only previous experience with this was modifying all of the descriptions to say the same thing as seen below.  But I'm not sure how to add a unique description to each computer account.  I had to do this from an Exchange server itself also.  I no longer have rights to log onto an Exchange server so must do it from my workstation with domain admin rights.

Previous .cmd I used to do a mass description change (run from Exchange Server):

@echo off
set ComputerList=C:\LocationOfMyComputerList.txt
for /f "delims=" %%a in ('type "%ComputerList%"') do (
  echo Processing %%a ...
  dsquery computer -name "%%a" | dsmod computer -desc "Mass Description Here"
)
0
Irrylyn
Asked:
Irrylyn
  • 2
1 Solution
 
SubsunCommented:
Try this code..
Import-Module Activedirectory
Import-Csv C:\computer.csv | %{
$Comp = $_
Write-Host "Working on $($Comp.Computer)"
 Try {
 Set-ADComputer $Comp.Computer -Description `
 ("$((Get-ADComputer $Comp.Computer -Pr Description -EA Stop).Description) $($Comp.SN)") -EA Stop
	New-Object PSObject -Property @{
	Computer = $Comp.Computer
	SN = $Comp.SN
	Update = "Success"
	}
 }
 Catch{
	New-Object PSObject -Property @{
	Computer = $Comp.Computer
	SN = $Comp.SN
	Update = "Failed"
	}
 }
} | Select Computer,SN,Update | Export-Csv c:\report.csv -nti

Open in new window

Sample csv file..
Computer,SN
ServerA,AAAAA
ServerB,BAAAA
ServerC,CAAAA 

Open in new window

0
 
IrrylynAuthor Commented:
This worked perfectly!!!  Thank you.  It updated the description without replacing anything that was previously there, and also spit out a results file!  Wonderful, thank you!

10k computer accounts updated in minutes!
0
 
SubsunCommented:
Nice!..
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now