?
Solved

Build smtp from company and name for special userids and company

Posted on 2013-06-07
2
Medium Priority
?
426 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
footech earned 2000 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
how to add IIS SMTP to handle application/Scanner relays into office 365.
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 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