Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Problems with Prepare-MoveRequest.ps1

$
0
0

Hi guys,

I am trying to execute Prepare-MoveRequests.ps1 in a powershell script and the command is not working properly. I store the command in a variable ($sCmd) and use invoke-expression $sCmd.

It returns the following error:

C:\Program Files\Microsoft\Exchange Server\V14\Scripts\Prepare-MoveRequest.ps1 : Error processing frederic@contoso.com, Mailbox not ready to move! Error message: The variable '$filterstring' cannot be retrieved because it has not been set.

However when I execute directly the same command from the command line it works without any issue.

For the details, we are performing a Cross Forest Migration with ADMT. After the account has been migrated some actions need to be performed in order to move the mailbox:

  1. Convert the user account to Mail Enable User (MEU)
  2. Prepare-MoveRequest to create all the Exchange attributes

Here is the CSV used by the script:

"Name","WindowsEmailAddress"
"Fred Test","fred@domain.com"

Here is the script:

[string] $TargetDeliveryDomain = "domain.com"
[string] $LocalDC = "DC1.corp.target.com"
[string] $RemoteDC = "DC1.source.local"
[string] $RemoteExchange = "EX1.source.local"

$RemoteCredentials = Get-Credential SOURCE\Administrator
$LocalCredentials = Get-Credential TARGET\Administrator

[string] $gsCurrentDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
$gsCSVFile = "$gsCurrentDirectory\$gsCSVFile"
Write-Verbose "General Settings - CSV File: $gsCSVFile"
if (Test-Path $gsCSVFile) {
    [string] $Name = ""
    [string] $WindowsEmailAddress = ""

    $goCSV = Import-Csv $gsCSVFile
    $goCSV | foreach {
        $Name = $_.Name.Trim()
        $WindowsEmailAddress = $_.WindowsEmailAddress.Trim()
        Write-Host "User: $($_.WindowsEmailAddress)"
       
        $oMailUser = Get-MailUser | Where-Object {$_.Name -eq $Name}
        if ($oMailUser -eq $null) {
            Write-Host "Enable-MailUser -Identity `"$Name`" -ExternalEmailAddress $WindowsEmailAddress"
            Enable-MailUser -Identity "$Name" -ExternalEmailAddress $WindowsEmailAddress
        } else {
            Write-Verbose "$Name is already a Mail Enabled User (MEU)."
        }

        Write-Host "Prepare Move Request..."
        $sCmd = ".\Prepare-MoveRequest.ps1 -Identity $WindowsEmailAddress -RemoteForestDomainController $RemoteDC -RemoteForestCredential `$RemoteCredentials -LocalForestDomainController $LocalDC -LocalForestCredential `$LocalCredentials -UseLocalObject -OverwriteLocalObject -Verbose"
       
        Write-Verbose $sCmd
        Set-Location "C:\Program Files\Microsoft\Exchange Server\V14\Scripts"
        Invoke-Expression $sCmd

    }

You will notice that I protect the 2 variables that stores the user credentials with a `. If I don't do it I am facing another issue:

C:\Program Files\Microsoft\Exchange Server\V14\Scripts\Prepare-MoveRequest.ps1 : Cannot process argument transformation
 on parameter 'RemoteForestCredential'. Cannot convert the "System.Management.Automation.PSCredential" value of type "System.String" to type "System.Management.Automation.PSCredential".
At line:1 char:139

I have tried different syntax to launch the command such as &, {} and & {}. All without success.

Honestly, I am clueless. After so many years using VBS, I really have difficulties to understand the logic behind Powershell sometimes. Especially the way it handle external commands.

Have you ever faced this kind of issue? Thank you very much for your help.

Regards, Fred


Viewing all articles
Browse latest Browse all 10624

Trending Articles