none
Exchange Import CSV script RRS feed

  • Question

  • 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"
    }
    }

    Monday, September 23, 2013 7:36 PM

Answers

  • @ Ed Crowley

    I tried what you had listed above but still was unable to get it to work. However, I changed it to get the display name instead of the first and last name. I was able to get the information when using the display name instead.   

    $User = Get-Mailbox -Identity $Mailbox.displayname -ResultSize Unlimited -ErrorAction SilentlyContinue | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" -and $_.displayname -eq $Mailbox.displayname }

    Tuesday, September 24, 2013 5:23 PM

All replies

  • Try changing the Get-Mailbox command to something like this:

    $Identity = $Mailbox.Last + " " + $Mailbox.First
    $User = Get-mailbox -Identity $Identity ...
    


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."

    Tuesday, September 24, 2013 3:10 AM
  • @ Ed Crowley

    I tried what you had listed above but still was unable to get it to work. However, I changed it to get the display name instead of the first and last name. I was able to get the information when using the display name instead.   

    $User = Get-Mailbox -Identity $Mailbox.displayname -ResultSize Unlimited -ErrorAction SilentlyContinue | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" -and $_.displayname -eq $Mailbox.displayname }

    Tuesday, September 24, 2013 5:23 PM