Asked by:
Unable to restore the SoftDeleted mailbox in O365

Question
-
Hi all,
I am creating a Windows Form with below function to restore the O365 soft deleted mailbox to a new created shared mailbox. Here's the function details:
function Restore { $ResignedEmail = $ResignedInput.Text $ResignedStillExist = Get-Mailbox -Filter {UserPrincipalName -eq $ResignedEmail} -ErrorAction SilentlyContinue if($ResignedStillExist -eq $null){ $ResultOutput.Text = echo "Mailbox $ResignedEmail is not exist, can continue.`r`n" $ResignedGUID = Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail | select Guid $ResignedMailboxName = Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail | select DisplayName $ResingedMailboxAlias = Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail | select Alias $NewMailboxAlias = ($ResingedMailboxAlias).Alias -replace '\s','' #Remove the space in Alias $NewMailboxName = ($ResignedMailboxName).DisplayName + "_Restored" $NewMailboxEmail = $ResignedInput.Text New-Mailbox -Name $NewMailboxName -Alias $NewMailboxAlias -Shared -PrimarySmtpAddress $NewMailboxEmail $NewMailboxGUID = Get-Mailbox -Identity $NewMailboxName | select GUID if ($NewMailboxGUID -eq $null) { $ResultOutput.Text = echo "Shared mailbox cannot be created" } else { New-MailboxRestoreRequest -SourceMailbox $ResignedGUID -TargetMailbox $NewMailboxGUID -AllowLegacyDNMismatch $ResultOutput.Text += echo "Resigned Staff mailbox has been restored." $ForwardToEmail = $ForwardToInput.Text Set-Mailbox $NewMailboxName -ForwardingAddress $ForwardToEmail -DeliverToMailboxAndForward $True $ResultOutput.Text += echo "Email forwarding has been done." } } else { $ResultOutput.Text = echo "$ResignedEmail is still exist, no actions taken. Please wait for the mailbox been removed.`r`n" } }
However, once I run it and the below errors occurs:
Cannot process argument transformation on parameter 'TargetMailbox'. Cannot convert value "@{MailboxGuid=c0xxxx-ae13-46fe-86dd-5c067xxxxxf4}" to type "Microsoft.Exchange.Configuration.Tasks.MailboxLocationIdParameter". Error: "Cannot convert hashtable to an object of the following type: Microsoft.Exchange.Configuration.Tasks.MailboxLocationIdParameter. Hashtable-to-Object conversion is not supported in restricted language mode or a Data section." + CategoryInfo : InvalidData: (:) [New-MailboxRestoreRequest], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-MailboxRestoreRequest + PSComputerName : ps.outlook.com
Cannot process argument transformation on parameter 'SourceMailbox'. Cannot convert the "3f7e91a-2bad-0433-fd04-e2ae8e83de24" value of type "System.Guid" to type "Microsoft.Exchange.Configuration.Tasks.MailboxLocationIdParameter". + CategoryInfo : InvalidData: (:) [New-MailboxResotreRequest], ParameterBindin...mationException + FullyQulifiedErrorId : ParameterArgumentTransformationError,New-MailboxRestoreRequest + PSComputerName : outlook.office365.com
I've tried to change the below script
$NewMailboxGUID = Get-Mailbox -Identity $NewMailboxName | select GUID
to be:
$NewMailboxGUID = Get-Mailbox -Identity $NewMailboxName | select ExchangeGUID
or to be:
$NewMailboxGUID = Get-MailboxLocation -Identity $NewMailboxName | select MailboxGuid
But all get the similar errors back.
Do you have any idea how can I fix this to let the function works? Thanks a lot!
- Moved by Kyle Wang - MSFTMicrosoft contingent staff Wednesday, March 13, 2019 7:46 AM about powershell
Wednesday, March 13, 2019 2:20 AM
All replies
-
Hi Lavenie,
According to the code you provided, your issue is more related about PowerShell. And this forum is discussing and asking questions about the Windows Form and ClickOnce. I will move this thread to corresponding forum: Windows PowerShell.
Thank you for your understanding.
Regards,
Kyle
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Wednesday, March 13, 2019 7:39 AM -
Hi,
Thanks for your question.
You can try this.
$NewMailboxGUID = (Get-MailboxLocation -Identity $NewMailboxName).GUID
Best regards,
Lee
Just do it.
Wednesday, March 13, 2019 7:54 AM -
Hi Lee,
Thanks for your help!!
however, after I changed the script as above, the Form displayed "Shared mailbox cannot be created", which means it triggered $NewMailboxGuid is null.
$NewMailboxGUID = (Get-MailboxLocation -Identity $NewMailboxName).GUID if ($NewMailboxGUID -eq $null) { $ResultOutput.Text = echo "Shared mailbox cannot be created" }
And if I changed as below,
$NewMailboxGUID = (Get-MailboxLocation -Identity $NewMailboxName).MailboxGUID if ($NewMailboxGUID -eq $null) { $ResultOutput.Text = echo "Shared mailbox cannot be created" }
The error becomes as this:
Cannot process argument transformation on parameter 'SourceMailbox'. Cannot convert value "@{Guid=0435dc-7ss3-4exx-bs3a-457c0sssss3}" to type "Microsoft.Exchange.Configuration.Tasks.MailboxLocationIdParameter". Error: "Cannot convert hashtable to an object of the following type: Microsoft.Exchange.Configuration.Tasks.MailboxLocationIdParameter. Hashtable-to-Object conversion is not supported in restricted language mode or a Data section." + CategoryInfo : InvalidData: (:) [New-MailboxRestoreRequest], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-MailboxRestoreRequest + PSComputerName : outlook.office365.com
Thank you!!
- Edited by Lavenie Friday, March 15, 2019 7:04 AM
Friday, March 15, 2019 6:33 AM -
Hi Lavenie,
When you run (Get-MailboxLocation -Identity $NewMailboxName).GUID, whether you can any output.
Also, you need to check $NewMailboxName. Try to just run $NewMailboxName, to check the output.
$ResignedGUID = (Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail).GUID $ResignedMailboxName = (Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail).DisplayName $ResingedMailboxAlias = (Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail).Alias
If you use select, you will get an aduser object with GUID/displayname property. If you use the code as I posted, you will save a string object with GUID value to the variable.
Best regards,
Lee
Just do it.
Friday, March 15, 2019 7:09 AM -
Hi Lee,
Thank you again!
I've tried few times these days, but I also got the same error:
Cannot process argument transformation on parameter 'SourceMailbox'. Cannot convert the "bb793a20-e334-48c9-b9ec-bbcd1f57677c" value of type "System.Guid" to type "Microsoft.Exchange.Configuration.Tasks.MailboxLocationIdParameter". + CategoryInfo : InvalidData: (:) [New-MailboxRestoreRequest], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-MailboxRestoreRequest + PSComputerName : outlook.office365.com
Here's my revised script:
function Restore { $ResignedEmail = $ResignedInput.Text $ResignedStillExist = Get-Mailbox -Filter {UserPrincipalName -eq $ResignedEmail} -ErrorAction SilentlyContinue if($ResignedStillExist -eq $null){ $ResultOutput.Text = echo "Mailbox $ResignedEmail is not exist, can continue.`r`n" $ResignedGUID = (Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail).ExchangeGUID $ResignedMailboxName = (Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail).DisplayName $ResingedMailboxAlias = (Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail).Alias $NewMailboxAlias = $ResingedMailboxAlias -replace '\s','' #Remove the space in Alias $NewMailboxName = $ResignedMailboxName + "_Restored" $NewMailboxEmail = $ResignedInput.Text New-Mailbox -Name $NewMailboxName -Alias $NewMailboxAlias -Shared -PrimarySmtpAddress $NewMailboxEmail $NewMailboxGUID = (Get-MailboxLocation -Identity $NewMailboxName).MailboxGUID $ResultOutput.Text = echo "New Mailbox $NewMailboxEmail created.`r`nResigned Mailbox GUID is: $ResignedGUID. `r`nNew Mailbox GUID is: $NewMailboxGUID`r`nAlias is: $NewMailboxAlias`r`nName is: $NewMailboxName`r`nEmail is: $NewMailboxEmail. `r`n" if ($NewMailboxGUID -eq $null) { $ResultOutput.Text = echo "Shared mailbox cannot be created" } else { New-MailboxRestoreRequest -SourceMailbox $ResignedGUID -TargetMailbox $NewMailboxGUID -AllowLegacyDNMismatch $ResultOutput.Text += echo "Resigned Staff mailbox has been restored.`r`n" $ForwardToEmail = $ForwardToInput.Text Set-Mailbox $NewMailboxName -ForwardingAddress $ForwardToEmail -DeliverToMailboxAndForward $True $ResultOutput.Text += echo "Email forwarding has been done." } } else { $ResultOutput.Text = echo "$ResignedEmail is still exist, no actions taken. Please wait for the mailbox been removed.`r`n" }
I've tried ExchangeGUID, GUID, and MailboxGUID, still same result.
$ResignedGUID = (Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail).ExchangeGUID $ResignedGUID = (Get-Mailbox -SoftDeletedMailbox -Identity $ResignedEmail).GUID
$NewMailboxGUID = (Get-MailboxLocation -Identity $NewMailboxName).MailboxGUID
$NewMailboxGUID = (Get-MailboxLocation -Identity $NewMailboxName).GUID
Do you still have any idea for the error? Thanks!!!
Wednesday, March 20, 2019 3:39 AM -
Hi,
I'm sorry for the delay.
Please refer the link below:
https://github.com/MicrosoftDocs/office-docs-powershell/issues/1763
Best regards,
Just do it.
Tuesday, April 9, 2019 1:32 PM