Collection of PowerShell traps and oddities
PowerShellTraps is a collection of some PowerShell traps and oddities shown by demo scripts, workarounds, and automated tests. On invoking scripts change to their directory. See also TESTS. Some scripts require Invoke-PowerShell.ps1.
-and
and -or
have the same precedence
-match
, -notmatch
do not reset $matches
[ref]
may be unwrapped unexpectedly
#requires
Close()
switch
is a looping construct
Throw
may not terminate
trap
creates a new scope
trap
with continue
trap
with no break
or continue
try
and trap
catch terminating errors
new()
ValidateScript
and cryptic error messages
process
block is called
WildcardPattern.Escape()
does not escape some backticks
OrderedDictionary
becomes Hashtable
ScriptBlock
becomes String
LiteralPath
in v2
ForEach-Object
Get-ChildItem
gets items converted to strings differently
Get-ChildItem
wildcard-path fails in a directory with backticks
Get-ChildItem -LiteralPath -Recurse
gets nothing for a directory with brackets
Get-ChildItem -Recurse
and missing -Path
unexpected search
Get-ChildItem -LiteralPath -Recurse
ignores -Include
Get-Unique
oddities
Import-Csv
may trim leading spaces
Join-Path
fails if the path drive does not exist
Remove-ItemProperty -Confirm
fails on 'No' (Registry)
Split-Path
with UNC paths: mind the current provider
Start-Process
Wait-Process
fails if a process name is not found
Where-Object
Write-Debug
Write-Progress
RootModule
Version
must be the first.
Version
and scriptblock host problem