I have a scenerio where a User is on Hold and he doesn't have OneDrive but only have Mailbox. If that's the case then I'm trying to update only for the Mailbox but some reason I'm getting an error something like " That person doesn't have OneDrive" and it's stop executing/updating.
I thought my try catch block already handle it to excute the script even if a user only have Mailbox but I'm not sure why I'm getting that error and not excuting.
How can I skip that error and only update user Mailbox anyway?. I'm not sure where I'm doing it wrong in my try catch block
try {
#Update Hold
$holdPolicy = Get-CaseHoldPolicy -identity $usr.GK -ErrorAction Stop
Write-Host "Hold Existed for $usr.GK"
if ($holdPolicy.isValid) {
#if the hold exist, compare their SMTP address to exchange Location
if ($holdPolicy.ExchangeLocation -ne $usr.PrimarySmtpAddress) {
#if the hold exist, Add or Update the hold.
$status = Get-CaseHoldPolicy -Identity $usr.GK -DistributionDetail
if ($status.DistributionStatus -ne "Pending") {
# policy no longer pending
$usr.GK + "HOLD Existed, Update Hold"
try {
# Try to Update both Mailbox and OneDrive
Write-Host ""
Set-CaseHoldPolicy -Identity $usr.GK -AddSharePointLocation $domain -AddExchangeLocation $usr.PrimarySmtpAddress -Comment $newComm
}
catch {
try {
#IT's not picking this for some reason
#If OneDrive not existed then UPDATE Mailbox only
Set-CaseHoldPolicy -Identity $usr.GK -AddExchangeLocation $usr.PrimarySmtpAddress -Comment $newComm
Write-Host "Updated Mailbox only"
}
catch {
try {
#If Mailbox not existed then UPDATE OneDrive only
Set-CaseHoldPolicy -Identity $usr.GK -AddSharePointLocation $domain -Comment $newComm
}
catch {
#If Both doesn't existed then put the name
Set-CaseHoldPolicy -Identity $usr.GK -Comment $newComm
}
}
}
}
else {
# policy still pending
Write-Host "Hold policy still pending."
}
}
}
}Catch{
#Add New HOLD
# SOME CODE
}