.net - 使用powershell向目录NTFS权限添加条件
问题描述
我想使用 PowerShell 将条件添加到文件夹的 NTFS 权限。PowerShell可以做到这一点吗?
我用谷歌搜索,但找不到任何东西。我创建一个脚本来添加或删除文件夹 ACL 中的规则没有问题。
这是我创建的一个函数,但想向 ACL 添加一个条件:
function AssignArchivePermissions($path){
$NTGroup="SG-ServerOperators"
$FileSystemRights="Modify"
$InheritanceFlags="ContainerInherit,ObjectInherit"
$PropagationFlags="None"
$AccessControlType="Allow"
$DenyGroup="CDIR-DenyDelete"
$acl = (get-item $path ).GetAccessControl('Access')
$aclst = $acl.Access
foreach($identity in $aclst.IdentityReference){
if($identity.Value -eq "domainname\$DenyGroup"){
$oldrule = New-Object System.Security.AccessControl.FileSystemAccessRule("domainname\$DenyGroup", $aclst.FileSystemRights,$aclst.InheritanceFlags,$aclst.PropagationFlags,$aclst.AccessControlType)
write-host "`n`r`n`r Removing $DenyGroup from $path ACL...`n`r"
$acl.RemoveAccessRule($oldrule)
}
}
try{
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("domainname\$NTGroup",$FileSystemRights,$InheritanceFlags,$PropagationFlags,$AccessControlType)
write-host "`n`r`n`r Adding $NTGroup to $path ACL...`n`r"
$acl.AddAccessRule($rule)
Set-Acl -Path $path -AclObject $acl
}
catch{}
}
解决方案
推荐阅读
- c# - 创建 Where 查询的 LINQ 扩展方法
- java - Spring Boot WebMvc 单元测试日期错误:perform() 返回日期早于预期(由于 GMT 假设)
- java - android relativelayout,一团糟
- hadoop - Sqoop 导入 - 连接到资源管理器时作业卡住
- c# - 如何在 C# 中从 XML 中获取属性
- django - 使用 django-extensions 插件在 jupyter notebook 中打印 sql 查询
- normalizr - 我如何在 normalizr.js 中表示多对多关系?
- javascript - 如何隐藏所有幻灯片并在 JavaScript 中显示当前幻灯片?
- asp.net - 何时从 Azure webapp 中清除临时 asp.net 文件
- typescript - 属性“安全”在文本字段中被忽略