Email dw Contents About dw
[Company Logo Image]

at The Data Center

"A space for AD, Exchange and other technical stuff"

 

 -- Where Information Technology Lives!  --

 


 

OK, all I wanted to do was change the properties of all users in an Organizational Unit. I find I use my vbscripting to do this all the time. I began to do this with powershell. As I couldn’t make it work, it started to become an obsession. To prevent the same thing from happening to you, here it is:
 
Here is a website that will tell you why it works, if ytour interested: http://www.microsoft.com/technet/scriptcenter/topics/winpsh/searchad.mspx
 
 
$vDom = ",dc=domain,dc=com"
$vOU = "ou=some OU"
$tel ="518-111-7777"
$vOUPath = $vOU + $vDom
$profilePath = "\\servername\share"
$strFilter = "(&(objectCategory=User))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = "LDAP://$vOUpath"
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "onelevel"
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
    {$objItem = $objResult.Properties; $objItem.name
    $n = $objItem.name
 $user=[ADSI]"LDAP://localhost:389/cn=$n,$vOUPath"
 $user.put("telephoneNumber", "$tel")
 $user.Put("profilePath", "$profilePath")
 $user.Put("mail", "$n@mydomain.com")
 $user.SetInfo()
}