PowerShell Flags & Options
Windows PowerShell 5.1 and PowerShell 7: shell, scripting language and the base of Microsoft 365 administration.All PowerShell pages
- ConvertTo-Json -Depth: why nested objects become strings like System.Collections.HashtableConvertTo-Json serializes only 2 levels by default and turns deeper objects into strings. Pass -Depth 10 (maximum 100) to keep nested data as real JSON.
- Export-Csv -NoTypeInformation: remove the #TYPE line from CSV filesWindows PowerShell 5.1 writes a #TYPE header as the first line of Export-Csv output unless you pass -NoTypeInformation. PowerShell 6+ omits it by default.
- Get-ChildItem -Recurse -Filter vs -Include: find files in subfoldersGet-ChildItem -Recurse -Filter *.log finds files in all subfolders. Tested: -Filter vs -Include and -Exclude, -Depth, and why -Include alone returns nothing.
- PowerShell -ErrorAction Stop: why try/catch does not catch the errortry/catch only catches terminating errors, and most cmdlet errors are not. Add -ErrorAction Stop, or set $ErrorActionPreference to Stop, to catch them.