2011-11-03 99 views

回答

0

看来,你可以找到指定至今保存在msSFU30MaxUidNumber属性上cn=yourYPDomain,cn=ypservers,cn=ypserv30,cn=RpcServices,cn=system,dc=dom,dc=fr的最高值。

这里给出一个脚本是:我'不能在我的配置,现在来测试它,我只是写一个简短的翻译从VBScript来的PowerShell中a Microsoft Consulting France document发现(第17页)。

# Get the Yellow page domain and his attribute msSFU30MaxUidNumber 
# dom.fr (dc=dom,dc=fr)is my domain 
# myYPDomain is the name of my yellow Page domain 
$ypDomain = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://societe.fr:389/cn=myYPDomain,cn=ypservers,cn=ypserv30,cn=RpcServices,cn=system,dc=dom,dc=fr","[email protected]","admin") 
#$msSFU30MaxUidNumber = $ypDomain.Properties["msSFU30MaxUidNumber"] 
$msSFU30MaxUidNumber = $ypDomain.msSFU30MaxUidNumber 

# Find a given user 
$dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://societe.fr:389/dc=dom,dc=fr","[email protected]","admin") 
$dsLookFor = new-object System.DirectoryServices.DirectorySearcher($dn) 
$dsLookFor.Filter = "(&(samAccountName=user1)(objectCategory=user))"; 
$dsLookFor.SearchScope = "subtree"; 
$n = $dsLookFor.PropertiesToLoad.Add("cn"); 
$n = $dsLookFor.PropertiesToLoad.Add("distinguishedName"); 
$Usr = $dsLookFor.findOne() 

# Assign new value 
$Usr.msSFU30MaxUidNumber = $msSFU30MaxUidNumber + 1 
$Usr.SetInfo() 

# Save the new Value 
$ypDomain.msSFU30MaxUidNumber = $msSFU30MaxUidNumber + 1 
$ypDomain.SetInfo() 
0

既然你的任务AD的cmdlet可用,这里是快速的基于JPBlanc的答案的东西。它假定您正在使用已经有权限对相关广告属性的帐户来运行脚本:

# The -IncludedProperties parameter is needed because msSFU30MaxUidNumber is not part of Get-QADObject's default attribute set 
$ypDomain = Get-QADObject -Identity "cn=myYPDomain,cn=ypservers,cn=ypserv30,cn=RpcServices,cn=system,dc=dom,dc=fr" -IncludedProperties msSFU30MaxUidNumber 

$maxUidNumber = $ypDomain.msSFU30MaxUidNumber 

$newMaxUidNumber = $maxUidNumber + 1 

# Sets the msSFU30UidNumber attribute for User1 

Get-QADUser -samAccountName User1 | Set-QADUser -objectAttributes @{msSFU30UidNumber = $newMaxUidNumber} 

# Increments the msSFU30MaxUidNumber for the YP domain. 

$ypDomain | Set-QADObject -objectAttributes @{msSFU30MaxUidNumber = $newMaxUidNumber} 
0

我借这个设置UNIX属性(NISDOMAIN,GID,登陆shell,UIDnumber,UID)http://danieltromp.com/2014/06/09/powershell-ad-enable-unix-attributes/

我更新了它,以便它也更新存储的msSFU30MaxUidNumber。我见过的所有脚本都忘记了这一点。 如果将来使用ADUC设置UNIX属性(或者即使您再次针对另一个OU运行脚本),也可以防止重复的UID编号问题:

Remove-Variable -Name * -Force -ErrorAction SilentlyContinue 
Import-Module ActiveDirectory 
$NIS = Get-ADObject "CN=DOMAIN,CN=ypservers,CN=ypServ30,CN=RpcServices,CN=System,DC=Domain,DC=com" -Properties:* #Get NIS server information 
$maxUid = $NIS.msSFU30MaxUidNumber #Get the last used User ID 

$usuarios = Get-ADUser -Filter * -SearchBase "OU=NAME,OU=NAME,OU=NAME,DC=Domain,DC=com" -Properties:* #Get all users 
foreach($usr in $usuarios) 
{ 
    if ($usr.mssfu30nisdomain -eq $null){ 
    Set-ADUser -Identity "$($usr.SamAccountName)" -Replace @{mssfu30nisdomain="Domain"} #Enable NIS 
    Set-ADUser -Identity "$($usr.SamAccountName)" -Replace @{gidnumber="10005"} #Set Group ID 
    Set-ADUser -Identity "$($usr.SamAccountName)" -Replace @{loginShell="/bin/bash"} #Set Login Shell 
    $maxUid++ #Raise the User ID number 
    Set-ADUser -Identity "$($usr.SamAccountName)" -Replace @{uidnumber=$maxUid} #Set User ID number 
    Set-ADUser -Identity "$($usr.SamAccountName)" -Replace @{uid=$usr.SamAccountName} #Set UID 
    Write-Host -Backgroundcolor Green -Foregroundcolor Black $usr.SamAccountName changed #Write Changed Username to console 
    } 
    else{Write-Host -Backgroundcolor Yellow -Foregroundcolor Black $usr.SamAccountName unchanged} #Write Unchanged Username to console with a yellow background 
} 
$NIS | Set-ADObject -Replace @{msSFU30MaxUidNumber = $maxuid++} 
$NIS | Set-ADObject -Replace @{msSFU30MaxUidNumber = $maxuid++} 
相关问题