powershell - PowerShell 和 foreach 循环
问题描述
我正在使用 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 个名称并更改权限。
解决方案
推荐阅读
- microsoft-graph-api - 使用 v2.0 和 v1.0 的 Mircosoft Graph API 身份验证令牌
- java - MyBatis SQL Builder 类 LIKE 与 %
- python - 如何在open3d中导入o3dtut
- drake - 在每个离散时间点从 MathematicalProgram 中围绕决策变量 (x, u) 线性化非线性系统的方法
- java - 如何在 Java 中使用字符串调用类的变量
- java - 获取字符数组的特定组合
- javascript - 检查元素是否包含在反应js中的对象数组中
- docker - 如何将代码从 Jenkins 服务器复制到它的 docker 代理
- macos - 如何从 NSDocument 中分离 NSTextView 的撤消管理器?
- javascript - 在 JavaScript 中递归二叉搜索树遍历结束时返回一个值