| pid | 1027 |
|---|---|
| author | Paul Brice |
| title | .displayName to .cn |
| date | 2009-04-14 15:27:06 -0700 |
| format | posh |
| parent | 0 |
Convert a list of user object displaynames to commonnames. This can be used to manually populate large distribution lists in the "Members" tab of an Active Directory user object.
Function ConvertUser
{
Process
{
ForEach($User In $_)
{
$strFilter = “(&(objectCategory=user)(displayName=$User))”
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = “Subtree”
$colUsers = $objSearcher.FindOne()
ForEach($objUser in $colUsers)
{
$objUser.properties.cn
}
}
}
}
Get-Content “C:\Scripts\Users.txt” | ConvertUser | Out-File “C:\Scripts\ConvertedUsers.txt”