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

use*_*879 3 scripting windows powershell active-directory csv

我正在尝试编写一个powershell脚本来更改comment使用csv和的电脑列表中名为“ ”的 属性import-Csv

在此处输入图片说明

这是我的脚本

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

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

在此处输入图片说明

但它跳到这个..

在此处输入图片说明

尝试谷歌搜索并在这里和那里更改,但不起作用!我对power-shell脚本了解甚少,但希望学习。有人可以指导我请什么我搞砸了?

小智 5

在您的 中for,您必须处理当前项目而不是computers集合。因此,您必须computers通过item以下方式更改命令:

Set-ADComputer -identity $item.DistinguishedName -add @{comment="bara"}
Run Code Online (Sandbox Code Playgroud)