Import-CSV "C:\text.csv" | ForEach {Enable-Mailbox -Identity $_.UPN -Database “Mailbox Database 1” -Alias $_.alias | Set-Mailbox -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $_.EmailAddress}
CSV File Format:
UPN | Alias | EmailAddress |
Ajay@contoso.com | Ajayk | Ajay.kakkar@contoso.com |
Alias: Alias name for the user(like:ajayk)
UPN: User logon name (like: ajayk@contoso.com)
Email Address: User email address(like: ajaykakkar@contoso.com)
Note: Alias and Email Address could be same or different as per your requirement.
I have a scenario, I would like to find if firstname and last name exist in org, in case yes, it should use middle name in SMTP policy and in case no, then use simple SMTP policy :
ReplyDeleteImport-Module ActiveDirectory -ErrorAction Stop
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
#Create Mailbox
$OU = "OU=Sync,OU=Users,OU=Corp,DC=domain,DC=com"
$sam = Get-aduser -filter * -Properties * | select CN
$FirstName = Get-aduser -filter * -Properties * | select GivenName
$LastName = Get-user -filter * -Properties *| select SN
$Middle = Get-Aduser -filter * -Properties * | select Initials
$EmailAddWithMiddle = ($FirstName+"."+$Middle+"."+$LastName+"@domain.com")
$EmailAddWithoutMiddle = ($FirstName+"."+$LastName+"@domain.com")
If ($Middle -eq "")
{
Get-User -ResultSize "Unlimited" -OrganizationalUnit $OU | Where-Object {$_.RecipientType -eq "User"} | Enable-Mailbox -Database DB2 | Set-Mailbox -EmailAddressPolicyEnabled $true
}
Else
{
Get-User -ResultSize "Unlimited" -OrganizationalUnit $OU | Where-Object {$_.RecipientType -eq "User"} | Enable-Mailbox -PrimarySmtpAddress $EmailAddWithMiddle -Database DB2
}