【发布时间】:2019-09-19 12:01:04
【问题描述】:
我正在使用 PowerShell 脚本来更改“内置用户”组的权限,基本上我需要将“修改”添加到一个文件夹中。我需要对大约 400 个系统执行此操作。我的电脑名称没有显示。
$computer = Get-Content -Path c:\computernames.txt
$user = "BUILTIN\Users"
$Rights = "Modify","Synchronize"
$InheritSettings = "Containerinherit, ObjectInherit"
$PropogationSettings = "None"
$RuleType = "Allow"
foreach ($computer in $computernames) {
$path = "\\$computer\C$\Program Files (x86)\Directory1\Directory2"
$acl = Get-Acl $path
$perm = $user, $Rights, $InheritSettings, $PropogationSettings, $RuleType
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $perm
$acl.SetAccessRule($rule)
$acl | Set-Acl -Path $path
}
我希望代码能够遍历文本文件中的所有 400 个名称并更改权限。
【问题讨论】:
-
foreach($computersystem in $computer),您已将 get-content 导入$computer并且路径看起来不正确,应该是类似“C:\ComputerNames.txt”的字符串 -
将
$path = "\\$computer\C`$\Program Files (x86)\Directory1\Directory2"移动到foreach循环体中。 -
你的路径没有被引用。
-
你更新的代码还是不行吗?它实际上是做什么的?请提供更多详细信息。
标签: powershell