无法编写Powershell函数以向用户授予文件夹权限

时间:2016-03-15 14:06:09

标签: powershell

我尝试编写此功能,但它不起作用。但是,当我从函数中排除正文时,它确实开始工作。我需要一个功能,它将添加用户并授予该文件夹完全权限。任何帮助将不胜感激。

function Grant-userFullRights {            
 Param(
  [string]$UserName,
  [string]$Files
)       
$Acl = Get-Acl $Files
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($UserName, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$Acl.SetAccessRule($Ar)
Set-Acl $Files $Acl
}

Grant-userFullRights "CHAD\sv_CS_CH", "G:\testing"

1 个答案:

答案 0 :(得分:2)

我认为你只是错误地运行了这个功能。尝试:

Grant-userFullRights -UserName "CHAD\sv_CS_CH" -Files "G:\Testing"