Mandy_
asked on
Build smtp from company and name for special userids and company
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@comp any.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.
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@comp
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.
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"
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER