I work with several large brown field PowerShell projects, which were developed by different peoples, both amateurs and pro in PS. I saw different, ugly and beautiful things.
The most confusing are one char syntax, that powershell is rich of. Some of this are common, some of this are rare and even redundant.
Here is short listing:
- # Explicit provider
- Get-Content -Path Function:prompt
- # Old good string format
- 'This is my post about {1} number {0}' -F 3, 'powershell'
- # Escaping
- "First line`r`nSecond one"
- # Explicit scope
- $Global:test = 'GlobalTest'
- # Hashtable
- $hash = @{ Name = 'Hashtable'; Description = 'Ordinary Collections.Hashtable'; }
- # Call operators
- & 'Get-Process'
- . 'Get-Process'
- # Use bool in switch argument
- $someBool = $true
- New-Item -Path Variable:SwitchTest -Value 1 -Verbose:$someBool
- # Simple scriptblock
- $sb = { Get-Process }
- # Foreach-Object and Where-Object aliases
- Get-Process | ?{ $_.PM -gt 1000 } | %{ $_.ProcessName }