Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Exchange Import CSV script

$
0
0

I'm having issues with my Exchange Import user script. I'm trying to enable UM on users mailbox using the script below. However, I'm not able to get the users mailbox using the import cmd. I would like get the users mailbox using their smtp address or display name. Please help.. 

CSV columns

First, Last, Primarysmtpaddress, pin, extension, operator, dialpolicy 

$DefaultPIN = 1152
 
# Set this to the location of the CSV file.
$mailboxes =  Import-CSV "UMsimple.csv"




 
 
# Call the Loop to Enable Users
Foreach ($mailbox in $mailboxes) {
 
# By default, Excel will have empty Alias Column so it will search by First Last.
if (!($mailbox.alias)) {
$User = Get-Mailbox -Identity ($Mailbox.Last + "" + " " + $Mailbox.First) -ResultSize Unlimited -ErrorAction SilentlyContinue | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" }
}
else {
$User = Get-Mailbox -Identity $Mailbox.PrimarySmtpAddress -ResultSize Unlimited -ErrorAction SilentlyContinue | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" -and $_.RecipientTypeDetails -eq $Mailbox.PrimarySmtpAddress}
}
 

if ($User) {
if ($User.Count -gt 1) {
Write-Warning $User "There are multiple users with this First Name and Last Name.  Go into the spreadsheet and provide the alias for the correct mailbox user"
}
else {
if ($User.UMEnabled -eq $false) {
Enable-UMMailbox -Identity $User.GUID.toString() -ummailboxpolicy $Mailbox.DialPolicy -pin $(if (!($mailbox.pin)) { $DefaultPIN } else { $Mailbox.PIN }) -pinexpired $true -Extensions $Mailbox.Extension -NotifyEmail $NotifyEmail
Set-UMMailbox -Identity $User.GUID.toString() -OperatorNumber $Mailbox.Operator
}
else {
Write-Host $User "is already enabled"
}
}
}
else {
Write-Host "ERROR:" ($Mailbox.First + "" + " " + $Mailbox.Last) "'s Mailbox Does Not Exist"
}
}


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>