Solved

Build smtp from company and name for special userids and company

Posted on 2013-06-07
2
418 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 39

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this video we show how to create a Distribution Group 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 Recipients >>…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now