Windows – import list of pcs using import-Csv and change attribute using powershell script

active-directorycsvpowershellscriptingwindows

Im trying to write a powershell script to change attribute called "comment" in a list of pcs using csv and import-Csv.

enter image description here

Here is my script

$computers=Import-Csv -Path "C:\sds.csv" 
foreach ($item in $computers){ 
Set-ADComputer -identity $computers.DistinguishedName -add @{comment="bara"}
}

and hear is my csv file located under "C:\sds.csv"

enter image description here

But it jumps in to this ..

enter image description here

Tried googling and changing here and there, yet does not work! I have very little understanding of power-shell script, yet wish to learn. Can someone guide me please what im messing up ?

Best Answer

In your for, you must work on the current item and not from the computers collection. So you must change in your command computers by item :

Set-ADComputer -identity $item.DistinguishedName -add @{comment="bara"}
Related Topic