Public/Migration/Test-PreFlightOnPrem.ps1
function Test-PreFlightOnPrem { param ( [Parameter(Mandatory = $true)] [String] $CsvFileName, [Parameter(Mandatory = $true)] [string] $Tenant ) if ($Tenant -match 'onmicrosoft') { $Tenant = $Tenant.Split(".")[0] } $Import = Import-Csv $CsvFileName foreach ($CurImport in $Import) { $UPN = "" $UPN = $CurImport.Check $CurImport.Check = $UPN if ($CurImport.PreFlightComplete -ne "TRUE") { try { $Mailbox = "" $Mailbox = Get-Mailbox -Identity $UPN -ErrorAction Stop $CurImport.RecipientType = $Mailbox.RecipientTypeDetails $CurImport.SamAccountName = $Mailbox.SamAccountName } catch { $WhyFailed = (($_.Exception.Message) -replace ",",";") -replace "\n","|**|" Write-Verbose "Error executing: Get-Mailbox $UPN" Write-Verbose $WhyFailed continue } if ($Mailbox.ForwardingAddress -ne $null) { $Forward = Get-Recipient $Mailbox.ForwardingAddress -ErrorAction $CurImport.ForwardingAddress = $Forward.PrimarySmtpAddress } else { $CurImport.ForwardingAddress = "Not Found" } try { $CasMailbox = Get-CASMailbox -Identity $UPN -ErrorAction Stop if ($CasMailbox.ActiveSyncEnabled -eq $true) { $CurImport.ActiveSyncEnabled = "TRUE" } else { $CurImport.ActiveSyncEnabled = "FALSE" } } catch { $WhyFailedCAS = (($_.Exception.Message) -replace ",",";") -replace "\n","|**|" $WhyFailed += $WhyFailedCAS Write-Verbose "Error executing: Get-CASMailbox $UPN" Write-Verbose $WhyFailedCAS } if ($WhyFailed) { $CurImport.ErrorOnPrem } } $Import | Export-Csv $CsvFileName -NoTypeInformation -Encoding UTF8 } } |