Powershell to Change Mailbox Alias to Equal SamAccountName
I have a number of mailboxes that have the alias formatted incorrectly. I want the alias to equal the samaccountname on all mailboxes.
How can I do that with powershell?
I tried the command below but it did not work.
get-mailbox -filter {Alias -like "*"} | ForEach{set-mailbox $_.Identity -Alias "$($_.SamAccountName)"}
September 4th, 2010 1:47pm
I don't think the user's samaccountname is a property of a mailbox object.
Try this (not tested):
get-mailbox -filter {Alias -like "*"} | ForEach{set-mailbox $_.Identity -Alias "$((get-user $_.distinguishedname).samaccountname)"}
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
September 4th, 2010 3:38pm
On Sat, 4 Sep 2010 10:47:06 +0000, DVDKEA wrote:
>I have a number of mailboxes that have the alias formatted incorrectly. I want the alias to equal the samaccountname on all mailboxes. How can I do that with powershell? I tried the command below but it did not work. get-mailbox -filter {Alias -like "*"}
| ForEach{set-mailbox $_.Identity -Alias "$($_.SamAccountName)"}
How does it "not work"? You'll get a warning (yellow text) when the
account name and the alias are already the same.
Adding a conditional so you don't try to change what doesn't need
changing the warnings will go away.
get-mailbox -filter {Alias -like "*"} | ForEach {if ($_.alias -ne
$_.samaccountname) {set-mailbox $_.Identity -Alias
"$($_.SamAccountName)"}}
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
September 4th, 2010 6:45pm
On Sat, 4 Sep 2010 12:38:39 +0000, mjolinor wrote:
> I don't think the user's samaccountname is a property of a mailbox object.
It is.
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
September 4th, 2010 6:45pm
Hi DVDKEA,
Said you want to change the alias to equal with the SamAccountName and the command provided by you cannot help you achieve your goal.
Could you please paste the error when you run the command or describe detailed how it does not work?
And I recommend you using the following script and try again.
[PS] C:\>$list=get-mailbox
[PS] C:\>foreach($item in $list)
>> {
>> $user=get-user $item
>> $sam=$user.SAMAccountName
>> Set-Mailbox $item -alias "$sam"
>> }
>>
Please feel free and let me know if the issue has not been resolved.
I am glad to have a further discussion with you.
Best regards,
Yang
September 6th, 2010 1:04pm