PowerShell try/catch Is Not Catching Your Error
Most cmdlet errors are non-terminating, so try/catch never sees them. Why -ErrorAction Stop is the whole trick, why Write-Error is not throw, and why try/catch does nothing at all for robocopy or git.
Most cmdlet errors are non-terminating, so try/catch never sees them. Why -ErrorAction Stop is the whole trick, why Write-Error is not throw, and why try/catch does nothing at all for robocopy or git.
Five things produce this error and only one is fixed by Set-ExecutionPolicy. The scope that is actually winning, the mark of the web that makes RemoteSigned refuse a file, and why fixing it in PowerShell 5.1 does nothing for PowerShell 7.
Your script asks for a column by the name on screen and gets an empty string back. Every column has two names, renaming never changes the one that matters, and Created By is called Author.
Updating a SharePoint list from a CSV fails in three ways, two of them silently: an invalid Choice value is written without complaint, an empty cell deletes data, and one bad cell loses the whole row. With the script that catches all three.
How to report everyone with access to a SharePoint site, and why the two obvious approaches are both wrong – one flags every site as overshared, the other stays silent while the whole company has Edit.
A tenant-wide site inventory with PowerShell, and why the owner column is harder than it looks: three of the four owner properties are empty on every site, and every group-connected site reports no owner at all.
A PnP PowerShell write costs 1.2 seconds. Batching makes inserts 19 times faster and updates only 3 times faster, and only ten cmdlets support it at all. Measured, with the throttling and retry pattern that goes with it.
Find every site, list, folder and item that does not inherit its permissions, and who has access to it. With the full script, the Forms folder that breaks the obvious approach, and a PnP switch that reports success while doing nothing.
How to read lists, items and files with PnP PowerShell, and the things that come back looking nothing like you expected: 19 lists on a site with 3, person fields that are not strings, and a version history one shorter than the file says.
PnP PowerShell has fifteen ways to authenticate. You need three of them. Which still work after September 2024, which are dead, and the deprecated one that is still the only method needing no app registration at all.