有谁知道一种方法来查询这个UNIX属性msSFU30MaxUidNumber 与Powershell Active Directory中?我正在开发一个脚本,根据需要为用户分配Unix属性。我也有Quest AD Powershell模块。如何使用Powershell查询msSFU30MaxUidNumber属性?
2
A
回答
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++}
相关问题
- 1. LDAP查询URL - 如何引用属性?
- 2. 如何提高使用EntitySet属性的LinqToSql查询的性能?
- 3. powershell - 如何设置属性
- 4. MongoDB:如何在查找查询中使用属性?
- 5. 查询属性
- 6. 查询与使用PowerShell
- 7. 使用PowerShell查询Active Directory
- 8. 如何查询使用EclipseLink @ReadTransformer和@WriteTransformer映射的@Entity属性的属性?
- 9. 使用xsd属性查询xml
- 10. SPARQL查询中使用属性
- 11. 如何查询从PowerShell的
- 12. 属性查询方法如何工作?
- 13. 查询子属性
- 14. 如何使用OCommandGremlin直接查询顶点属性?
- 15. 如何使用JS API查询JSON以返回JSON属性?
- 16. 如何在Pharo上使用MongoTalk查询嵌套属性?
- 17. 坚持JDO - 如何使用JDOQL查询集合的属性?
- 18. 如何使用JSONField中的属性查询Django中的模型?
- 19. 如何使用NHibernate查询具有嵌套属性的对象?
- 20. 如何从使用Linq到XML的属性查询xsi:type?
- 21. 如何使用存储文档中的属性运行查询?
- 22. 如何使用Xml REST查询中的Xml属性填充ListBox?
- 23. 绿岛如何使用一个查询的四个属性
- 24. 如何使用其中一个属性查询对象ID为
- 25. MDX查询 - 如何使用成员属性?
- 26. 如何使用Cypher在Neo4j中查询破折号的属性
- 27. 如何从使用PostgreSQL的查询中获取列属性?
- 28. 1563的Python SDK - 如何使用“查询”属性,UsersClient get_users方法
- 29. 如何在Linq查询中使用我的模型属性?
- 30. 如何在LINQ-to-Entities查询中使用自定义属性?