Try/Catch works in PowerShell ISE and not in PowerShell console
I recently encountered an issue with one of my PowerShell scripts. It was a script to enable litigation hold on all mailboxes in Exchange Online.
I connected to Exchange Online via the usual means below.
$creds = Get-Credential $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Creds -Authentication Basic -AllowRedirection Import-PSSession $session -AllowClobber
I then attempted to execute the following with no success.
try { Set-Mailbox -Identity $user.UserPrincipalName -LitigationHoldEnabled $true -ErrorAction Stop } catch { Write-Host "ERROR!"… [Keep reading] “Try/Catch works in PowerShell ISE and not in PowerShell console”