Read computer description from csv or txt file and put in AD

Hello All,

I'm new to scripting and have enjoyed all I've done with it so far. The issue at hand is, we would like to add a description to all our servers. I can get a .csv or .txt file with the computer name and description. Is it possible to pull a computer name from AD, match that 'computer name' with one in my .csv file and import the corresponding 'description' into AD ?

I look forward to suggestions on how to get started with this. Thank you.

RD

September 1st, 2015 10:13am

Hi there,

something like this should match your needs:

Import-Module ActiveDirectory $computers = Import-Csv -Path C:\temp\export\CompDescriptions.csv foreach ($comp in $computers)

{ Set-ADComputer ($comp.Name) -Description ($comp.Description) }



CSV with "Name" and "Description"

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 10:30am

Thank you David,

I believe with a bit of tweaking I can make this work. Excellent.

September 1st, 2015 12:08pm

David,

I can get this to work as long as my .csv file has only 1 entry. If more than 1 entry it will run the script with no errors but does not populate the description field in AD

This .csv works

Name,Description

Server1,Description of Server1

This .csv will not work

Name,Description

Server1,Description of Server1

Server2,Description of Server2

Can you help with this? 

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 11:02am

David's script should work no matter how many entries you have in your input CSV, as it uses a loop.

Are you sure you're not just seeing a replication delay?

September 2nd, 2015 11:09am

Mike

I tried waiting 15 mins but still no description field is populated. When I try it with only 1 line in the csv, I can see the field populated immediately. So not sure on this.

Thanks, Rod

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 12:31pm

I'd add a trace inside the loop for testing purposes:

Import-Csv .\computerDesc.csv | ForEach {

    Write-Host "Setting $($_.Name) description to $($_.Description)" -ForegroundColor Green
    Set-ADComputer $_.Name -Description $_.Description

}
September 2nd, 2015 12:38pm

Not sure how fast the replication happens in your environment - You can do a quick check using below code

Import-Csv .\computerDesc.csv | ForEach {

    Write-Host "Setting $($_.Name) description to $($_.Description)" -ForegroundColor Green
    Set-ADComputer $_.Name -Description $_.Description -Server "DC.Domain.com"

}

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 12:53pm

Possibly I have problems with my csv file?

Name,Description

Server1,description server1

Server2,description server2

Do you mind posting your entire script that worked for you?

September 2nd, 2015 12:57pm

Do you mind posting your entire script that worked for you?

I ran exactly what I posted above. My input was as such:

Name,Description
TESTCOMP1,Description for 1
TESTCOMP2,Description for 2

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 12:59pm

OK thank you. I'll give it another try.
September 2nd, 2015 1:04pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics