Script to add Exchange 2007 Description field to the Title Field only does the first 1000 contacts
We originally had an Exchange 2003 server and for some reason when we created a custom Contacts OU somebody put all the contacts titles under the description field. Since then we have added an Exchange 2007 server with the 2003 server. Since this server addition our staff has been adding the contacts title under the title field. Odd part is in Exchange Management Console the description field is not natively shown (you can only see it in AD). So we need a script that will copy the contacts descriptions field (if field contains data) to the contacts title field (only if title field is null). so we ran script in exchange powershell (we have 5000 contacts) Get-Contact|foreach {$ADobject=[adsi]("LDAP://" + $_.DistinguishedName);$Desc=$ADobject.Description.Value;$Title=$_.Title;If (($Title -eq '') -and ($Desc -ne $null)) {Set-Contact -Id $_.Identity -Title $Desc}} This script seemed to work fine for the first 1000 contacts, the contacts in the start all added the title from the description line, HOWEVER However you get a warning back only the first 1000 contacts will affected unless you add -ResultSize Unlimited so we ran Get-Contact -ResultSize Unlimited|foreach {$ADobject=[adsi]("LDAP://" + $_.DistinguishedName);$Desc=$ADobject.Description.Value;$Title=$_.Title;If (($Title -eq '') -and ($Desc -ne $null)) {Set-Contact -Id $_.Identity -Title $Desc}} but not all the contacts change, it feels like only the first 1000 users are changing. tested by deleting the title and adding a description to the the first contact, about the middle contact and the last contact. Only the first contact had a title. Any ideas?
May 16th, 2010 8:20am

On Sun, 16 May 2010 05:20:11 +0000, Charlie Batch wrote: > > >We originally had an Exchange 2003 server and for some reason when we created a custom Contacts OU somebody put all the contacts titles under the description field. Since then we have added an Exchange 2007 server with the 2003 server. Since this server addition our staff has been adding the contacts title under the title field. Odd part is in Exchange Management Console the description field is not natively shown (you can only see it in AD). So we need a script that will copy the contacts descriptions field (if field contains data) to the contacts title field (only if title field is null). > >so we ran script in exchange powershell (we have 5000 contacts) > >Get-Contact|foreach {$ADobject=[adsi]("LDAP://" + $_.DistinguishedName);$Desc=$ADobject.Description.Value;$Title=$_.Title;If (($Title -eq '') -and ($Desc -ne $null)) {Set-Contact -Id $_.Identity -Title $Desc}} > >This script seemed to work fine for the first 1000 contacts, the contacts in the start all added the title from the description line, HOWEVER > >However you get a warning back only the first 1000 contacts will affected unless you add -ResultSize Unlimited > >so we ran > >Get-Contact -ResultSize Unlimited|foreach {$ADobject=[adsi]("LDAP://" + $_.DistinguishedName);$Desc=$ADobject.Description.Value;$Title=$_.Title;If (($Title -eq '') -and ($Desc -ne $null)) {Set-Contact -Id $_.Identity -Title $Desc}} > >but not all the contacts change, it feels like only the first 1000 users are changing. tested by deleting the title and adding a description to the the first contact, about the middle contact and the last contact. Only the first contact had a title. > > > >Any ideas? Is it possible that the title property is somthing other than an empty string? You might want to change the condition to: $Title.length -match "^ *$" I'd also change the "[adsi]" to "[ADSI]". I don't know if that makes a difference in this case, but I recall reading that some of the casts were case-sensitive. You could also add a bit of code to write the results of the modification, or lack of it, to a file. Knowing what the values are that you're working with, and under what conditions things work, or don't, is very helpful when things don't work the way you thing they should. Maybe something like this? {$ADobject=[ADSI]("LDAP://" + $_.DistinguishedName); $Desc=$ADobject.Description.Value; $Title=$_.Title; $Changed = $false; $Name = $_.name If (($Title -match "^ *") -and ($Desc -ne $null)) { Set-Contact -Id $_.Identity -Title $Desc $Changed = $true } "$Name`t$Desc`t$Title`tChanged" | out-file change.log -append } --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
May 16th, 2010 7:34pm

I think you need to change: $Title -eq '' to $Title -eq $Null -- Ed Crowley MVP "There are seldom good technological solutions to behavioral problems." . "Charlie Batch" wrote in message news:8e1325fb-69fb-4b4b-805d-8752e20020c7... We originally had an Exchange 2003 server and for some reason when we created a custom Contacts OU somebody put all the contacts titles under the description field. Since then we have added an Exchange 2007 server with the 2003 server. Since this server addition our staff has been adding the contacts title under the title field. Odd part is in Exchange Management Console the description field is not natively shown (you can only see it in AD). So we need a script that will copy the contacts descriptions field (if field contains data) to the contacts title field (only if title field is null). so we ran script in exchange powershell (we have 5000 contacts) Get-Contact|foreach {$ADobject=[adsi]("LDAP://" + $_.DistinguishedName);$Desc=$ADobject.Description.Value;$Title=$_.Title;If (($Title -eq '') -and ($Desc -ne $null)) {Set-Contact -Id $_.Identity -Title $Desc}} This script seemed to work fine for the first 1000 contacts, the contacts in the start all added the title from the description line, HOWEVER However you get a warning back only the first 1000 contacts will affected unless you add -ResultSize Unlimited so we ran Get-Contact -ResultSize Unlimited|foreach {$ADobject=[adsi]("LDAP://" + $_.DistinguishedName);$Desc=$ADobject.Description.Value;$Title=$_.Title;If (($Title -eq '') -and ($Desc -ne $null)) {Set-Contact -Id $_.Identity -Title $Desc}} but not all the contacts change, it feels like only the first 1000 users are changing. tested by deleting the title and adding a description to the the first contact, about the middle contact and the last contact. Only the first contact had a title. Any ideas? Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
May 16th, 2010 7:36pm

I see what you are driving at but I am unsure how to add that to my script
Free Windows Admin Tool Kit Click here and download it now
May 17th, 2010 7:34am

I also see your point but it made no difference.
May 17th, 2010 7:35am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics