3

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 ?

user879
  • 269
  • 2
  • 6
  • 21

1 Answers1

5

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"}
Sorcha
  • 1,315
  • 8
  • 11