none
Not able to set LitigationHoldEnabled as true RRS feed

  • Question

  • I am trying to set true to LitigationHoldEnabled and getting following error. I am using following code. Please advise what wrong I doing or my approach incorrect

    mport-Csv  "D:\pscript\users.csv" | foreach {
            $Mailbox = Get-Mailbox -Identity $_.userPrincipalName -ErrorAction SilentlyContinue
            If ($Mailbox) {
                Write-Host $_.userPrincipalName "Mailbox exists"
            } 
            Else { 
                Write-Host $_.userPrincipalName "Mailbox does not exists"
                New-MoveRequest -Identity $_.userPrincipalName -Remote -RemoteHostName webmail2.myconnect.net -TargetDeliveryDomain mycon.mail.onmicrosoft.com -RemoteCredential $msol -BadItemLimit 50 -LargeItemLimit 50 -AcceptLargeDataLoss -warningaction "SilentlyContinue"
    
                Write-Host $_.userPrincipalName "Mailbox Migration is started"
                
                #Settingup Litigation & Hold
                Set-Mailbox -Identity $_.userPrincipalName -LitigationHoldEnabled $true
        
                    Write-Host "------------------------------------------------------------------------------"
                    Start-Sleep 60
            }

    ============Error

    WARNING: If you want to change LitigationHoldEnabled and LitigationHoldDuration on an inactive mailbox, please add the
    InactiveMailbox switch.
    The operation couldn't be performed because object 'Test-Mailbox888@domain.com' couldn't be found on
    'domain.PROD.OUTLOOK.COM'.
        + CategoryInfo          : NotSpecified: (:) [Set-Mailbox], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : [Server=asdasdROM,RequestId=187adsd1a1f6-1060-407a-888d-f6basdasd6c28a8,TimeStamp=31/08/201
       6 5:24:46 PM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 7858EA80,Microsoft.Exchange.Management.Re
      cipientTasks.SetMailbox
        + PSComputerName        : outlook.office365.com


    Friday, September 2, 2016 7:25 AM

Answers

  • Hi Avian,

    that's just the thing - it worked for me. To troubleshoot this, try running this:

    Import-Csv  "D:\pscript\users.csv" | ForEach-Object {
    	$Mailbox = Get-Mailbox -Identity $_.userPrincipalName -ErrorAction SilentlyContinue
    	If ($Mailbox)
    	{
    		Write-Host $_.userPrincipalName "Mailbox exists"
    	}
    	Else
    	{
    		Write-Host $_.userPrincipalName "Mailbox does not exists"
    		New-MoveRequest -Identity $_.userPrincipalName -Remote -RemoteHostName webmail2.myconnect.net -TargetDeliveryDomain mycon.mail.onmicrosoft.com -RemoteCredential $msol -BadItemLimit 50 -LargeItemLimit 50 -AcceptLargeDataLoss -warningaction "SilentlyContinue"
    		
    		Write-Host $_.userPrincipalName "Mailbox Migration is started"
    		
    		Write-Host "------------------------------------------------------------------------------"
    		Start-Sleep 60
    		while (Get-MoveRequest)
    		{
    			$MoveRequests = Get-MoveRequest -identity $_.userPrincipalName | Get-MoveRequestStatistics
    			$Host.EnterNestedPrompt()
    			foreach ($MoveRequest in $MoveRequests)
    			{
    				switch ($MoveRequest.status)
    				{
    					"InProgress"    {
    						Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
    					}
    					
    					"CompletionInProgress" {
    						Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
    					}
    					
    					
    					"Queued" {
    						Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
    					}
    					
    					"Completed"     {
    						Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status"
    						#Settingup Litigation & Hold
    						Set-Mailbox -Identity $_.userPrincipalName -LitigationHoldEnabled $true
    					}
    				}
    			}
    		}
    	}
    }

    with a single entry in your csv. This will return you to a prompt, after retrieving the MoveRequest statistics. Inspect the variables, try out things - this allows you to put your hand on the raw objects as they are processed.

    Just inspect all variables, it might well be that you can find the issue while doing so.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, September 6, 2016 7:14 AM

All replies

  • Hi Avian,

    Move-Requests aren't magic that teleports your data from one server to another - I've heard Microsoft was trying to hire him, but Scotty likes his Star-travelling life too much to change occupation. You may want to make sure, the move has been finished before trying to edit its stats.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Friday, September 2, 2016 8:24 AM
  • HI FWN

    Thanks for reply.

    I put the logic to check therequest  status as well, if move-request statusis  completed then only LitigationHoldEnabled  set to true, but I am till getting error. I posted same question in Office 365 forum as well someone replied that it is issue with script. I am not sure what is the issue, can any one help me out here.

    Avian

    Friday, September 2, 2016 11:02 AM
  • Hi Avian,

    instead of setting the litigation hold, can you use Get-Mailbox to find the mailbox?

    If you have logic in your original script that verifies the move-request is done, please post the full script.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Friday, September 2, 2016 11:33 AM
  • Hello

    Here is the original script

    Import-Csv  "D:\pscript\users.csv" | foreach {
        $Mailbox = Get-Mailbox -Identity $_.userPrincipalName -ErrorAction SilentlyContinue
        If ($Mailbox) {
            Write-Host $_.userPrincipalName "Mailbox exists"
        } 
        Else { 
            Write-Host $_.userPrincipalName "Mailbox does not exists"
            New-MoveRequest -Identity $_.userPrincipalName -Remote -RemoteHostName webmail2.myconnect.net -TargetDeliveryDomain mycon.mail.onmicrosoft.com -RemoteCredential $msol -BadItemLimit 50 -LargeItemLimit 50 -AcceptLargeDataLoss -warningaction "SilentlyContinue"
    
            Write-Host $_.userPrincipalName "Mailbox Migration is started"            
        
            Write-Host "------------------------------------------------------------------------------"
            Start-Sleep 60
            while (Get-MoveRequest)
                    {
                        $MoveRequests = Get-MoveRequest -identity $_.userPrincipalName | Get-MoveRequestStatistics
                        foreach ($MoveRequest in $MoveRequests) {
                            switch ($MoveRequest.status) { 
                                "InProgress"    { 
                                    Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"                             
                                }
    
                                "CompletionInProgress" {
                                    Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
                                }
    
    
                                "Queued" {
                                    Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
                                }
    
                                "Completed"     {
                                    Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status"
                                #Settingup Litigation & Hold
                                Set-Mailbox -Identity $_.userPrincipalName -LitigationHoldEnabled $true
                                }
                            }
                        }
                    }
                }
            }

    IN above script I never got status message in while (Get-MoveRequest) loop, it seems I am missing something looks like never ending loop. Infact I wait for 60 min to get the any of the status message but never got. But when checked the status in PowerShell command prompt, it was shown as completed.  So I remove the while loop code and tested LitigationEnabled logic but unfortunately no luck.

    Please advise

    Avian



    • Edited by Avian123 Friday, September 2, 2016 3:13 PM
    Friday, September 2, 2016 2:50 PM
  • Hi Avian,

    well, that's curious: Had no trouble making that work for me (mind you, there are some more things that need tweaking in general, but the basic loop should work and display infos. Note, generally you need to remove a MoveRequest, once it's completed.

    While not the root cause of this, your Write-Host strings need some fixing as well:

    # Bad
    Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
    
    # Better
    Write-Host "INFO: Move request for $($_.userPrincipalName) Status is $($MoveRequests.status) and as of now $($MoveRequest.PercentComplete)% is completed"

    Basically, if you want to access the property of an object within a string, you need to wrap the entire call in $(...).

    Also note, that your loop is an infinity-loop. You should somehow end it when you have done what needs doing (but first of course you need to find out what the hell is going wrong). Try running this line by line directly on the console.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Monday, September 5, 2016 7:22 AM
  • Hi Fred

    Thanks for suggestion for Write-Host string.

    However I am still not able to understand, why  in while (Get-MoveRequest)    loop nothing is returning. I debug following lines, but it is not going anywhere just keep running. Not sure how handle this?

    $MoveRequests = Get-MoveRequest -identity $_.userPrincipalName | Get-MoveRequestStatistics
                        foreach ($MoveRequest in $MoveRequests) {
                            switch ($MoveRequest.status) { 

    Regards

    Avian

    Monday, September 5, 2016 5:28 PM
  • Hi Avian,

    that's just the thing - it worked for me. To troubleshoot this, try running this:

    Import-Csv  "D:\pscript\users.csv" | ForEach-Object {
    	$Mailbox = Get-Mailbox -Identity $_.userPrincipalName -ErrorAction SilentlyContinue
    	If ($Mailbox)
    	{
    		Write-Host $_.userPrincipalName "Mailbox exists"
    	}
    	Else
    	{
    		Write-Host $_.userPrincipalName "Mailbox does not exists"
    		New-MoveRequest -Identity $_.userPrincipalName -Remote -RemoteHostName webmail2.myconnect.net -TargetDeliveryDomain mycon.mail.onmicrosoft.com -RemoteCredential $msol -BadItemLimit 50 -LargeItemLimit 50 -AcceptLargeDataLoss -warningaction "SilentlyContinue"
    		
    		Write-Host $_.userPrincipalName "Mailbox Migration is started"
    		
    		Write-Host "------------------------------------------------------------------------------"
    		Start-Sleep 60
    		while (Get-MoveRequest)
    		{
    			$MoveRequests = Get-MoveRequest -identity $_.userPrincipalName | Get-MoveRequestStatistics
    			$Host.EnterNestedPrompt()
    			foreach ($MoveRequest in $MoveRequests)
    			{
    				switch ($MoveRequest.status)
    				{
    					"InProgress"    {
    						Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
    					}
    					
    					"CompletionInProgress" {
    						Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
    					}
    					
    					
    					"Queued" {
    						Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status and as of now $MoveRequest.PercentComplete% is completed"
    					}
    					
    					"Completed"     {
    						Write-Host "INFO: Move request for $_.userPrincipalName Status is $MoveRequests.status"
    						#Settingup Litigation & Hold
    						Set-Mailbox -Identity $_.userPrincipalName -LitigationHoldEnabled $true
    					}
    				}
    			}
    		}
    	}
    }

    with a single entry in your csv. This will return you to a prompt, after retrieving the MoveRequest statistics. Inspect the variables, try out things - this allows you to put your hand on the raw objects as they are processed.

    Just inspect all variables, it might well be that you can find the issue while doing so.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, September 6, 2016 7:14 AM