I am calling PnP-GetWeb
like this:
[Microsoft.SharePoint.Client.SecurableObject]$Web = Get-PnPWeb -Connection $pnpConnection -ErrorAction SilentlyContinue
if($null -eq $web) {
throw "Could not get information for: $($pnpConnection.Url)"
}
but when there is a 403 “Forbidden”, it only outputs this to stdout. There is no exception thrown and I don’t see a way to capture that error information unless I redirect stdout. It seems I need to capture its error output to a variable instead of to stdout so that I can format the error before logging it.
I this I can capture error output to a variable like this:
$output = Get-PnpWeb -Connection $pnpConnection 2>&1
but how do I both assign $web and $output?