Solved

Build smtp from company and name for special userids and company

Posted on 2013-06-07
2
423 Views
Last Modified: 2013-06-09
Hi,

in the script below i need to exclude user with special IDs and special company to
write the smtp adresses of this special user into a other form as all other.
The form of the smtp should be

firstname.lastname.zp@company.com  nothing more. every user should have
a "ZP" after firstname.lastname

pls see what i did in line 16 - 21 in the script. Is that correct?
All other user smtp should be build like in the lines behind. line 25....

In the attached CSV you see an example (line 5).
All other informations given in the csv colums "name"  behind like (Z0000) or (extern) not should be use to build the smtp.
example see user id and company field

Import-Csv c:\import1.csv | ForEach `
{
    $_.name.ToLower() -match "^(?<last>[a-z -]+),( (?<middle>[a-z]+))? (?<first>[a-z-]+)( (?<code>[a-z0-9()]+))?$" | Out-Null
    $first = $matches["first"] -replace "[^a-z]","."
    $middle = $matches["middle"] -replace "[^a-z]","."
    $middle2 = $matches["middle"] -replace "[^a-z]","."
    $last = $matches["last"] -replace "[^a-z]","."
    $code = $matches["code"] -replace "[()]"
    $company = $data[$_.company]
    If ($middle)
    { $middle = "." + $middle }
    If ($code)
    { $code = "." + $code }
    
    
   {$_.UserId -like "Z0*" -or $_.UserId -like "Z8" -and $_.Company -like "REX*"} {
    
    $newSMTP = "{0}{1}{2}.{3}{4}@{5}" -f $first,$last,ZP,$company
    #$ADUser = Get-ADUser -identity $_.UserID -Properties Company  
    $mbox = Get-Mailbox $_.UserID
    $mbox


    
    $newSMTP = "{0}{1}{2}.{3}{4}@{5}" -f $first,$middle,$middle2,$last,$code,$company
    $mbox = Get-Mailbox $_.UserID
    $mbox
   
    
        If ($mbox.PrimarySMTPAddress -ne $newSMTP)
        {
            Write-Host  -ForegroundColor Green "Setting primary SMTP $newsmtp address for $mbox "
	        $newsmtp | out-file -filepath c:\smtp4.csv -append
            set-mailbox -identity $_.UserID -PrimarySmtpAddress $newsmtp -EmailAddressPolicyEnabled $false
		} else {
            Write-Host -ForegroundColor red -backgroundcolor yellow "$mbox has an SMTP-Address already exists in system"
		}
    
}

Open in new window

0
Comment
Question by:Mandy_
2 Comments
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39232119
I don't understand what $middle2 is for, but that wasn't your question...
The following should work for what you want.  Just replace lines 16-25 with the below.
    If ($_.UserId -like "Z0*" -or $_.UserId -like "Z8" -and $_.Company -like "REX*") {
        $newSMTP = "{0}.{1}.{2}@{3}" -f $first,$last,"zp",$company
        #$ADUser = Get-ADUser -identity $_.UserID -Properties Company  
        $mbox = Get-Mailbox $_.UserID
        $mbox
    }
    Else {
        $newSMTP = "{0}{1}{2}.{3}{4}@{5}" -f $first,$middle,$middle2,$last,$code,$company
    }

Open in new window

0
 
LVL 2

Author Closing Comment

by:Mandy_
ID: 39232617
Thank you so much. Thats it!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question