我有一个脚本可以将文件夹复制到网络上的计算机,但有时我需要为它们设置权限。我在下面测试了这个脚本,它适用于一台机器,但它不会为其他机器工作,它只是挂起。知道为什么这不起作用吗?
# This is the file that contains the list of computers you want
# to modify permissions to. Change this path IAW your folder structure.
$computers = gc "C:\scripts\computers.txt"
# This is the folder you want to modify.
$source = "c$\AEM"
foreach ($computer in $computers) {
if (test-Connection -Cn $computer -quiet) {
"Modifying for $computer"
$acl = Get-Acl \\$computer\$source
$acl.SetAccessRuleProtection($True, $True)
# This is where you set the permissions you want, Modify the group (the first object) and the rights (the second object) as needed.
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Users","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl \\$computer\$source $acl
} else {
"$computer is not online"
}
}
就其功能而言,它非常简单。它发送到远程机器并留下继承,所以我不会覆盖任何东西。然后它添加我指定的权限,并应循环回来,直到我修改了文本文件中列出的所有计算机。当我复印时工作得很好,在一台机器上工作得很好,但是当我在我们的一个培训室的其他机器上试用它时,它在第一个机器上失败了。我错过了什么吗?我有通过网络的管理访问权限,所以并不是说我没有权限这样做。
答案 0 :(得分:0)
该脚本实际上按预期工作,虽然没有进度条,但似乎它没有做任何事情。应用回声和进度条。