.NET Framework - adding smtp address for all users containing the employeeID field

Asked By Steven V
18-Mar-10 11:15 AM
Hi All,

I need a PS Scipt that scans my AD for users with the EmployeeID filled out
and that uses the number within that field to set a secondairy SMTP address
as in: "<EmployeeID>@somedomain.com"

Scrounging for bits and pieces on this and other forums I came up with:

Get-Mailbox -ResultSize Unlimited -Filter {employeeID -eq "<number>"} |
foreach {
$user = get-user $_
$email = "{0}@somedomain.com" -f $user.employeeID
$_.EmailAddresses+= $email
$_
} | Set-Mailbox

(I know, it should not be "-eq", it should be something else ...)
btw: I am running AD 2003 R2 and Exchange 2007 sp1 and completely new to
Powershell.

Thanks in advance for any tips and tricks!

Best regards,
Steven
--
Sorry ''bout that, I thought you said "Powersmell" ...
TestForAddress
(1)
SMTP
(1)
DistinguishedName
(1)
EmailAddresses
(1)
SmtpAddress
(1)
ResultSize
(1)
EmployeeID
(1)
NewSmtp
(1)
  Chris Dent replied to Steven V
19-Mar-10 04:00 PM
Something like this should work. it is a bit silly, but it is easier to
add e-mail addresses using ADSI unless I am missing something glaringly
obvious about Set-Mailbox.


Get-Mailbox -ResultSize Unlimited -Filter {employeeID -eq "<number>"} | %{
$User = Get-User $_
$NewSmtp = "{0}@somedomain.com" -f $User.employeeID

$TestForAddress = $_.EmailAddresses | ?{ $_.SmtpAddress -Like $NewSmtp }

If ($TestForAddress -eq $Null)
{
$User = [ADSI]"LDAP://$($_.DistinguishedName)"
$User.PutEx(3, "proxyAddresses", @("smtp:$NewSmtp"))
$User.SetInfo()
}
}
Create New Account