我正在做一個powershell腳本,它在AD中創建新的域用戶帳戶,並在相關權限的文件服務器中創建主目錄。Powershell腳本爲用戶創建主文件夾並設置權限
我的問題是我無法獲得權限設置。
在下面的代碼中,my_fileServer是文件服務器名稱; sso表示單點登錄ID,在下面的測試代碼中設置爲「user9999」。
任何幫助,非常感謝!
Set-Variable homeDir -option Constant -value "\\my_fileServer\Users"
Set-Variable sso -option Constant -value "user9999"
# If the folder for the user does not exist, make a new one and set the correct permissions.
if ((Test-Path "$homeDir\$sso") -eq $false)
{
try
{
$NewFolder = New-Item -Path $homeDir -Name $sso -ItemType "Directory"
$Rights = [System.Security.AccessControl.FileSystemRights]"FullControl,Modify,ReadAndExecute,ListDirectory,Read,Write"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objUser = New-Object System.Security.Principal.NTAccount "my_full_domain_name\$sso"
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
($objUser, $Rights, $InheritanceFlag, $PropagationFlag, $objType)
$ACL = get-acl -Path $NewFolder
$ACL.AddAccessRule($objACE)
$objReturn = Set-ACL -Path "$homeDir\$sso" -AclObject $ACL
$objReturn
}
catch
{
$msg = $_
$msg
}
}
主文件夾被創建好,但是當我檢查用戶的權限時,沒有勾選框。
Set-Acl不返回一個值。 – 2013-02-15 11:25:00