Board logo

标题: [转载代码] [PowerShell每日技巧]调用icacls.exe设置NTFS权限(20140321) [打印本页]

作者: DAIC    时间: 2014-4-3 09:41     标题: [PowerShell每日技巧]调用icacls.exe设置NTFS权限(20140321)

There are many ways to add or change NTFS permissions. One is to reuse existing tools such as icacls.exe.

This function will create new folders that have default permissions. The script uses icacls.exe to explicitly add full permissions to the current user and read permisssions to local Administrators:
  1. function New-Folder
  2. {
  3.   param
  4.   (
  5.     [String]
  6.     $path,
  7.     [String]
  8.     $username = "$env:userdomain\$env:username"
  9.   )
  10.   If ( (Test-Path -Path $path) -eq $false )
  11.   {
  12.     New-Item $path -Type Directory | Out-Null
  13.   }
  14.   icacls $path /inheritance:r /grant '*S-1-5-32-544:(OI)(CI)R' ('{0}:(OI)(CI)F' -f $username)
  15. }
复制代码
http://powershell.com/cs/blogs/tips/archive/2014/03/21/applying-ntfs-access-rules.aspx




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