Board logo

标题: [技术讨论] PowerShell修改ACL设置文件安全权限 [打印本页]

作者: DAIC    时间: 2013-11-4 15:28     标题: PowerShell修改ACL设置文件安全权限

增加权限
  1. $filePath = "D:\Test\a.txt"
  2. $account = "Everyone"
  3. $FileSystemRights = "FullControl"
  4. $objType = [System.Security.AccessControl.AccessControlType]::Allow
  5. $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($account,$FileSystemRights,$objType)
  6. $acl = Get-Acl $filePath
  7. $acl.SetAccessRule($accessRule)
  8. Set-Acl -Path $filePath -AclObject $acl
复制代码
删除权限
  1. $filePath = "D:\Test\a.txt"
  2. $account = "Everyone"
  3. $FileSystemRights = "FullControl"
  4. $objType = [System.Security.AccessControl.AccessControlType]::Allow
  5. $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($account,$FileSystemRights,$objType)
  6. $acl = Get-Acl $filePath
  7. $acl.RemoveAccessRule($accessRule)
  8. Set-Acl -Path $filePath -AclObject $acl
复制代码





欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2