Tôi đang thực hiện kịch bản lệnh PowerShell tạo tài khoản người dùng miền mới trong AD và cũng tạo thư mục chính trong máy chủ tệp có quyền phù hợp.Kịch bản Powershell tạo thư mục nhà cho người dùng và quyền thiết lập
Vấn đề của tôi là tôi không thể nhận được quyền được đặt.
Trong mã bên dưới, my_fileServer là tên máy chủ tệp; sso nghĩa là id đăng nhập một lần, trong mã thử nghiệm bên dưới được đặt thành "user9999".
Bất kỳ trợ giúp nào được đánh giá cao!
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
}
}
Thư mục chính được tạo OK, nhưng khi tôi kiểm tra quyền cho người dùng, không có hộp nào được chọn.
Set-Acl không trả về giá trị. –