导入使用import-Csv的pcs列表并使用powershell脚本更改属性

我试图编写一个powershell脚本来改变使用csvimport-Csv的电脑列表中的名为“ comment ”的属性。

在这里输入图像说明

这是我的脚本

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

听到是我的csv文件位于"C:\sds.csv"

在这里输入图像说明

但它跳到这..

在这里输入图像说明

试图用googlesearch和改变,但不起作用! 我对power-shell脚本的理解很less,但是希望学习。 有人可以指导我什么即时搞乱?

在你for ,你必须在当前的项目,而不是从computers集合。 所以你必须改变你的命令computersitem

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