Powershell - Pipeline (Functional Programming)

About

Management

Current Object

The current object is represented by the $_ symbol.

Map

Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | 
Format-Table –AutoSize


gc log.txt | %{ $_ -replace '\d+', '($0)' }         # sed
gc log.txt | %{ ($_ -split '\s+')[3] }   # Get the 4th element separated by space
  • for each
Get-Children . | ForEach-Object {
    Write-Host $_
}

Filter

Get-OdbcDriver | 
Select Name, Platform, Attribute | 
Where-Object {$_.Name -like '*SQL Server*' -and ($_.Platform -eq '64-bit')}

gc log.txt | select -first 10 # head
gc log.txt | select -last 10  # tail
gc log.txt | more             # or less if you have it installed

Count

  • Return the count property
@(Get-Alias).Count
  • Or
$m = get-alias | measure
$m.Count

Unique

$a | sort -unique
select -uniq ?

Powered by ComboStrap