Kullanıcıların ev adreslerinin doğru olup olmadığını ve doğru yolu ayarlamamış olup olmadığını denetleyen bir komut dosyası yapıyorum. OU-1, OU-2'den farklı bir yola sahiptir ve bazı kullanıcılar bir istisnadır. Ama senaryo çalışmıyor.Çoklu OU'lar için farklı homedirectories nasıl ayarlanır?
$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++
}