Export powershell results for aliases that have spaces
- Hey guys needs some help double checking this. We have several occurances where there is a space in the alias of mailboxes/contacts/DLs which is not allowed anymore. I would like to export the mailboxes/contacts/DLs with this issue to a csv file so that i have some record of what mailboxes/DLs had issues before I just blow through all of them.
Thanks!!
Mike
Can i use this for mailboxes:
Get-Mailbox | Where {$_.Alias -like "* *"} | out-file "c:\mailboxresults.csv"
Then run this to fix the problem:
Get-Mailbox | Where {$_.Alias -like "* *"} | ForEach-Object {Set-Mailbox $_.Name -Alias:($_.Alias -Replace " ","")}
For DLs
get-distributiongroup | Where {$_.Alias -like "* *"} | out-file "c:\dlresults.csv"
Then run this to fix the problem:
Get-distributiongroup | Where {$_.Alias -like "* *"} | ForEach-Object {Set-distributiongroup $_.Name -Alias:($_.Alias -Replace " ","")}
For contacts:
Get-contact | Where {$_.Alias -like "* *"} | out-file "c:\contactresults.csv"
Then run this to fix the problem:
Get-contact | Where {$_.Alias -like "* *"} | ForEach-Object {Set-contact $_.Name -Alias:($_.Alias -Replace " ","")}
Answers
- Does Get-Mailbox | Where {$_.Alias -like "* *"} actually show any mailboxes that you want to modify?
I'd speed the process up useing a filter like:
Get-Mailbox -filter {Alias -like "* *"} -ResultSize Unlimited | out-file "c:\mailboxresults.csv"
Now, you could also do it like this:
$mailboxes = Get-Mailbox -filter {Alias -like "* *"} -ResultSize Unlimited
$mailboxes | ForEach-Object {Set-Mailbox $_.Name -Alias:($_.Alias -Replace " ","")}
$mailboxes | Export-Csv "c:\mailboxresults.csv" -NoTypeInformation
Etcetera
Note that the Set-Mailbox is untested.
Karl- Proposed As Answer byXiu Zhang - MSFTMSFT, ModeratorWednesday, November 04, 2009 7:08 AM
- Marked As Answer byJames-LuoMSFT, ModeratorFriday, November 13, 2009 9:13 AM
The Exchange Team has already addressed this issue with a PowerShell script
Exchange 2007 Scripting Corner: fix-alias
http://msexchangeteam.com/archive/2007/06/15/441802.aspx
http://msexchangeteam.com/files/438479/download.aspxExcerpt from the Function ShowHelp
Write-host "This script will find objects of the specified type that contain a space in the alias"
Write-host "It will remove the space from the alias and update the object"
Write-host " "
The base fix-it code is very short. You can easily customize it for your needs. You should use Export-Csv if you really want a comma-delimited file (with foreign characters add -Encoding 'Unicode') and import from it. Out-File redirects screen output to a file, just as >.
For instance:
C:\>Get-MailContact | Select Name, Alias, PrimarySmtpAddress | Export-Csv -Encoding 'Unicode' c:\temp\ng_contacts.csvThe result could be:
#TYPE System.Management.Automation.PSCustomObject
Name,Alias,PrimarySmtpAddress
"Jon-Alfred Smith (contact)",Jon-AlfredSmith_contact,xxx@me.com
"Julie Smith (contact)",JulieSmith_contact,xxx@me.comDelete the first line and import it as an Unicode .csv file in Excel.
MCTS: Messaging | MCSE: S+M | Small Business Specialist- Proposed As Answer byXiu Zhang - MSFTMSFT, ModeratorThursday, November 05, 2009 2:16 AM
- Marked As Answer byJames-LuoMSFT, ModeratorFriday, November 13, 2009 9:13 AM
All Replies
- Does Get-Mailbox | Where {$_.Alias -like "* *"} actually show any mailboxes that you want to modify?
I'd speed the process up useing a filter like:
Get-Mailbox -filter {Alias -like "* *"} -ResultSize Unlimited | out-file "c:\mailboxresults.csv"
Now, you could also do it like this:
$mailboxes = Get-Mailbox -filter {Alias -like "* *"} -ResultSize Unlimited
$mailboxes | ForEach-Object {Set-Mailbox $_.Name -Alias:($_.Alias -Replace " ","")}
$mailboxes | Export-Csv "c:\mailboxresults.csv" -NoTypeInformation
Etcetera
Note that the Set-Mailbox is untested.
Karl- Proposed As Answer byXiu Zhang - MSFTMSFT, ModeratorWednesday, November 04, 2009 7:08 AM
- Marked As Answer byJames-LuoMSFT, ModeratorFriday, November 13, 2009 9:13 AM
The Exchange Team has already addressed this issue with a PowerShell script
Exchange 2007 Scripting Corner: fix-alias
http://msexchangeteam.com/archive/2007/06/15/441802.aspx
http://msexchangeteam.com/files/438479/download.aspxExcerpt from the Function ShowHelp
Write-host "This script will find objects of the specified type that contain a space in the alias"
Write-host "It will remove the space from the alias and update the object"
Write-host " "
The base fix-it code is very short. You can easily customize it for your needs. You should use Export-Csv if you really want a comma-delimited file (with foreign characters add -Encoding 'Unicode') and import from it. Out-File redirects screen output to a file, just as >.
For instance:
C:\>Get-MailContact | Select Name, Alias, PrimarySmtpAddress | Export-Csv -Encoding 'Unicode' c:\temp\ng_contacts.csvThe result could be:
#TYPE System.Management.Automation.PSCustomObject
Name,Alias,PrimarySmtpAddress
"Jon-Alfred Smith (contact)",Jon-AlfredSmith_contact,xxx@me.com
"Julie Smith (contact)",JulieSmith_contact,xxx@me.comDelete the first line and import it as an Unicode .csv file in Excel.
MCTS: Messaging | MCSE: S+M | Small Business Specialist- Proposed As Answer byXiu Zhang - MSFTMSFT, ModeratorThursday, November 05, 2009 2:16 AM
- Marked As Answer byJames-LuoMSFT, ModeratorFriday, November 13, 2009 9:13 AM
- Thanks guys I think I have what I need now!!
Mike - Hi,To remove '#TYPE System.Management.Automation.PSCustomObject' from a csv result just add -NoTypeInformation to Export-Csv Cmdlet as Karl used in above post like thisExport-Csv "c:\mailboxresults.csv" -NoTypeInformationRegards,
Laeeq Qazi|Snr Software Engineer(Exchange + Sharepoint + BES + DynamicsCRM) http://HostingController.com


