I hesitate to enumerate my list of PowerShell one-liners one by one as the list numbers just about 400 entries at present! :-) But here are a few of my favorites, to pique your interest:
- List all type accelerators (requires [PSCX][1]): `[accelerators]::get`
- Convert a string representation of XML to actual XML: `[xml]"<root><a>...</a></root>"`
- Dump an object (increase depth for more detail): `$PWD | ConvertTo-Json -Depth 2`
- Recall command from history by substring (looking up earlier 'cd' cmd): `#cd`
- Access C# enum value: `[System.Text.RegularExpressions.RegexOptions]::Singleline`
- Generate bar chart (requires Jeff Hicks' [cmdlet][2]): `ls . | select name,length | Out-ConsoleGraph -prop length -grid`
The whole collection is publicly available in a 4-part series published on Simple-Talk.com -- I hope that these will be useful to SO readers!
- Part 1: [Help, Syntax, Display and Files][3]
- Part 2: [Variables, Parameters, Properties, and Objects][4]
- Part 3: [Collections and Hash Tables][5]
- Part 4: [Files and Data Streams][6]
I wanted to call the series *"Do Anything in One Line of PowerShell"* but my editor wanted something more terse, so we went with *PowerShell One-Liners*. Though in the interests of full disclosure, only 98% or so are really one-liners in the true spirit of the term; I thought that was close enough with rounding... :-)
[1]:
[To see links please register here]
[2]:
[To see links please register here]
[3]:
[To see links please register here]
[4]:
[To see links please register here]
[5]:
[To see links please register here]
[6]:
[To see links please register here]