[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Build smtp from company and name for special userids and company

Posted on 2013-06-07
2
Medium Priority
?
427 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 41

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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

649 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