Skip to main content

Posts

Showing posts from September, 2017

Useful Powershell stuff

Add a calculated property to a list of objects, along with all the other properties:
    Select *,@{Name="ExtraField;Expression={$_.SomeValue+1}}

Get a list of drives, including network drives and their UNC paths (like with "net use"):
    Get-WmiObject -Class win32_logicaldisk

Get previous session history with "get-history"
Run a previous command without pushing up 1000 times with "invoke-history"

csi = C# interactive (custom alias)

Formatting:
get a list of every property and value for an object:
    $whatever | Format-List
Prevent output from truncating:
    Format-Table -AutoSize -Wrap

Redirection:
& { blah } 1 > $null    - suppress standard output from executing "blah". More info
$var = & Do-Stuff *>&1  - redirect all output to standard output and store that in $var
& { whatever } 2>$null 3>$null - redirect error and warning streams

Output:
get-content .\somefile -Wait  - tail-like behaviour, displays additi…