locked
How to cut a specific name up to the @ character RRS feed

  • Question

  • Hello guys,

    I would like to write a script that reads all active emails and then cuts it at the @ character and exports this in a Excel then create a new alias with the string before the at and a specific domain at the end.

    I hope that you can help me!

    Best regards

    Matthias

    Friday, September 12, 2014 8:06 AM

All replies

  • Matthias - 

    I presume you are looking to do this in PowerShell?  If so, I've used the split property of a string to do this before.  For example:

    $mbx = get-mailbox john.doe

    $mbx.PrimarySMTPAddress.Split("@")[0]

    The split function tells PowerShell to break it apart at the @ sign.  The result is an array with two entries.  The local part of the email address would be the first entry in the array (position zero)

    -Gary


    Gary Steere | Microsoft Certified Master: Exchange Server | Microsoft Certified Solutions Master: Messaging | Microsoft vTSP

    Friday, September 12, 2014 4:13 PM
  • Hello Matthias,

    Agree with Gary. You can use Split function to get the alias before @.

    However I would replace on the fly with replace function and get everything ready in csv file.

    Get-Mailbox -ResultSize Unlimited | Select DisplayName, PrimarySmtpAddress, @{name="NewSMTPAddress";expression={$_.PrimarySmtpAddress.tostring() -replace "domainabc","domainxyz"}} | export-csv c:\export.csv

    Friday, September 12, 2014 6:03 PM
  • You have more solution.

    My example

    $mailbox = (Get-Mailbox).WindowsEmailAddress

    foreach($alias in $mailbox)
    {
        $alias.Replace('@domain.com','')
    }


    Saturday, September 13, 2014 1:42 PM
  • thanks all,probably will need this one day,so will tag it as usefull.then it will be easier to find back to this thread :)


    Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you. Thank you! Off2work

    Saturday, September 13, 2014 4:32 PM
  • Thank you guys,

    I would be very pleased if you mark my question as helpful.

    Is it also possible to get the other alias addresses from powershell and not just the primary one?

    Best regards

    Matthias

    Tuesday, September 16, 2014 7:51 AM