Exchange Server TechCenter > Exchange Server Forums > Admin > Export powershell results for aliases that have spaces
Ask a questionAsk a question
 

AnswerExport powershell results for aliases that have spaces

  • Tuesday, November 03, 2009 3:42 PMMike_work Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Tuesday, November 03, 2009 4:39 PMKarl Mitschke Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

  • Wednesday, November 04, 2009 6:22 PMJon-Alfred Smith Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.aspx

    Excerpt 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.csv

    The 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.com

    Delete the first line and import it as an Unicode .csv file in Excel.


    MCTS: Messaging | MCSE: S+M | Small Business Specialist

All Replies

  • Tuesday, November 03, 2009 4:39 PMKarl Mitschke Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

  • Wednesday, November 04, 2009 6:22 PMJon-Alfred Smith Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.aspx

    Excerpt 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.csv

    The 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.com

    Delete the first line and import it as an Unicode .csv file in Excel.


    MCTS: Messaging | MCSE: S+M | Small Business Specialist
  • Thursday, November 05, 2009 2:22 PMMike_work Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks guys I think I have what I need now!!

    Mike
  • Saturday, November 07, 2009 2:26 PMLaeeq Qazi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 this  

            Export-Csv "c:\mailboxresults.csv" -NoTypeInformation


         Regards,

         
       

    Laeeq Qazi|Snr Software Engineer(Exchange + Sharepoint + BES + DynamicsCRM) http://HostingController.com