我正在构建一个脚本,用于检查用户的path目录是否正确,如果不正确,则设置正确的路径。OU-1的路径与OU-2不同,一些用户是个例外。但是脚本不起作用。
这就是我到目前为止得到的:
$folderpath = "\\172.16.32.27\gebruikers\homedir\", "\\172.16.32.27\share\homedirectories\"
$homedrive = "H"
$SearchBase = "OU=test,DC=Test,DC=org", "OU=users,DC=Test,DC=org"
$domain = "test.org"
$excludes = @("test", "user22")
$i = 0
$filter3 = "homedirectory -notlike '$("$homepath[$i]")' -and samaccountname -ne '$($excludes -join "' -and samaccountname -ne '")'"
$SearchBase | foreach {
Get-ADUser -SearchBase $_ -Filter $filter3 -Properties HomeDirectory, UserPrincipalName, Homedrive, samaccountname | % {
$homedirectory = "$($folderpath[$i])$($_.SamAccountName)"
if (!(Test-Path -Path $homedirectory)) {
New-Item -Type Directory -Path $homedirectory
$acl = Get-Acl -Path $homedirectory
$permission = $_.UserPrincipalname, 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow'
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission
$acl.SetAccessRule($rule)
$permission = "$domain\Domain Admins", 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow'
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission
$acl.SetAccessRule($rule)
Set-Acl -Path $homedirectory -AclObject $acl
Set-ADUser $_ -HomeDirectory "$homedirectory" -HomeDrive $homedrive
} elseif ($_.HomeDirectory -ne "$homedirectory*" -or $_.Homedrive -ne "$homedrive") {
Set-ADUser $_ -HomeDirectory "$homedirectory" -HomeDrive $homedrive
}
}
$i++
}发布于 2016-04-04 22:40:57
如果在OU和主目录之间创建映射:
$homeShares = @{
'OU=test,DC=Test,DC=org' = '\\172.16.32.27\gebruikers\homedir'
'OU=users,DC=Test,DC=org' = '\\172.16.32.27\share\homedirectories'
}您可以像这样处理它们:
foreach ($ou in $SearchBase) {
Get-ADUser -SearchBase $ou ... | ForEach-Object {
$homedirectory = Join-Path $homeShares[$ou] $_.SamAccountName
if (Test-Path ...) {
...
}
}
}也就是说,IMHO更简洁的方法是将所有主目录放在单个共享下,调整该共享文件夹的(NTFS)权限,如下所示:
并使用简单的登录脚本自动创建缺少的主目录。在批处理中,它看起来有点像这样:
if not exist \\server\share\%username% mkdir \\server\share\%username%但您也可以使用VBScript或PowerShell。
在此基础上启用Access-based Enumeration,您的用户不仅可以访问自己的主页,甚至不会看到其他任何人的主页。
https://stackoverflow.com/questions/36404214
复制相似问题