Export powershell results for aliases that have spaces
Hey guys needs some help double checking this. We have several occurances where there isa space in the alias of mailboxes/contacts/DLs which is not allowed anymore. I would like to export the mailboxes/contacts/DLswith 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!!MikeCan 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 DLsget-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 " ","")}
November 3rd, 2009 6:42pm

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" -NoTypeInformationEtceteraNote that the Set-Mailbox is untested.Karl
Free Windows Admin Tool Kit Click here and download it now
November 3rd, 2009 7:39pm

The Exchange Team has already addressed this issue with a PowerShell scriptExchange 2007 Scripting Corner: fix-aliashttp://msexchangeteam.com/archive/2007/06/15/441802.aspxhttp://msexchangeteam.com/files/438479/download.aspx Excerpt from the Function ShowHelpWrite-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.csv The result could be: #TYPE System.Management.Automation.PSCustomObjectName,Alias,PrimarySmtpAddress"Jon-Alfred Smith (contact)",Jon-AlfredSmith_contact,xxx@me.com"Julie Smith (contact)",JulieSmith_contact,xxx@me.com Delete the first line and import it as an Unicode .csv file in Excel. MCTS: Messaging | MCSE: S+M | Small Business Specialist
November 4th, 2009 9:22pm

Thanks guys I think I have what I need now!!Mike
Free Windows Admin Tool Kit Click here and download it now
November 5th, 2009 5:22pm

Hi, To remove '#TYPE System.Management.Automation.PSCustomObject' from a csv result just add -NoTypeInformation to Export-Csv Cmdletas Karl used in above post like this Export-Csv"c:\mailboxresults.csv" -NoTypeInformation Regards, Laeeq Qazi|Snr Software Engineer(Exchange + Sharepoint + BES + DynamicsCRM) http://HostingController.com
November 7th, 2009 5:26pm

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

Other recent topics Other recent topics