我希望能得到一些指导。
我有一个csv文件,有两列“path”和“所有者”
我已经创build了belkow脚本,它可以从trhe CSV文件中读取,但是当我尝试从csv分配variables时,失败。
我看不出我要去哪里错了。 任何帮助,将不胜感激。
import-csv c:\test\output.csv | foreach-object { $Path = $_.path $owner =$_.owner "The username is $Path and the owner is $owner" } ForEach-Object { $Path = $_.path $owner =$_.owner $Account = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList '$owner'; $Acl = Get-Acl -Path $path ; $Acl.SetOwner($Account); Set-Acl -Path $owner -AclObject $Acl; }
输出从第一部分正确,并显示path和所有者,但第二部分不根据path设置所有者。
谢谢
第二个foreach没有input对象来迭代。 所以要么
$csv = import-csv c:\test\output.csv $csv | foreach-object { $Path = $_.path $owner =$_.owner "The username is $Path and the owner is $owner" } $csv | ForEach-Object { $Path = $_.path $owner =$_.owner $Account = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList "$owner" $Acl = Get-Acl -Path $path $Acl.SetOwner($Account); Set-Acl -Path $Path -AclObject $Acl }