notag

Filter and Compare

Filtering Get-ADComputer -filter "Name -like '*DC'" Filter left The best place to filter is in the first command. Where-Object Get-Service | Where-Object -filter { $_.Status -eq 'Running' } Get-Service | Where Status -eq 'Running' Get-Service | Where Name -like '*print*' Get-Process | where name -NotLike 'powershell*' Get-Service | Where-Object -filter { $_.Status -eq 'Running' -and $_.StartType -eq 'manual' } Get-Process | where {$_.ws -gt 10mb} Comparison Operators -eq - Equality -ne - Not Equal -ge and -el - Greater,less than or equal -gt and -lt - Greater than or less than Case sensitive versions -ceq, -cne, -cgt, -clt, -cge, -cle See other Operators. »

Variables

Use variable in text $svc = Get-Service browser "The $($svc.displayname)service is $($svc.status)" »

Operators

Comparison Operators Operator Description Example -eq (-ne) Equal (Not Equal) $a –eq 8 -gt Greater than 10 –gt $b -ge Greater than or equal 123 –ge 321 -lt Less than $a –lt $b -le Less than or equal $a –le $c -Like (-NotLike) Wildcard string comparison $name –like “*shell” -Match (-NotMatch) Regular expression comparison $name –match “shell$” -Contains (-NotContains) Does an array contain a value? »

Core Commands

Read file content Get-Content whathappend.log #Alias cat, type, gc cat file.txt | where {$_} # filter empty lines Last or first x items Get-Content file.txt -head 20 Get-Content file.txt -tail 10 Get-Content file.txt -tail 1 -Wait #wait at the and and show new lines Search for folders and files Get-Childitem #alias dir, ls, gci dir c:\ -File #Only files dir c:\ -Directory #Only directories dir c:\temp dir c:\temp -recurse #Search for a file or filder dir \\chi-fp01\it\*. »

Custom Objects

Examples Get all processes and create a new object layout. Create a object Runtime by calculating the runtime from the start time. get-process | where starttime | Select ID,Name,Starttime, @{Name="RunTime";Expression={(Get-Date) - $_.StartTime}} | Sort RunTime »

Microsoft

AzureAzure ADAzure policiesAzure SubscriptionsManage Azure resources and groupsPowershellPowershell StorageManage Shares with PowershellPowershell RemotePowershell NetworkingPowershell and FirewallCommandsPsreadlineTest ConnectionTest NetconnectionBeginningFirt StepsPowershell HelpPowershell Providers Psdrive Manage Files and FoldersSelecting and Sorting ObjectsFormattingFilter and ComparePipelineVariablesOperatorsCore CommandsCustom ObjectsPowershell Regular ExpressionsWindows Server »

Awsome lists

https://github.com/kahun/awesome-sysadmin/blob/master/README.md#editors https://github.com/clowwindy/Awesome-Networking/blob/master/README.md https://github.com/Kickball/awesome-selfhosted/blob/master/README.md https://github.com/briatte/awesome-network-analysis/blob/master/README.md https://github.com/cisco-ie/awesome-network-programmability/blob/master/readme.md https://github.com/cisco-ie/awesome-network-programmability/blob/master/readme.md https://github.com/enaqx/awesome-pentest/blob/master/README.md »

Psreadline

Image at bottom does not work!! This module replaces the command line editing experience in PowerShell.exe for versions 3 and up. It provides: Syntax coloring Simple syntax error notification A good multi-line experience (both editing and history) Customizable key bindings Cmd and emacs modes (neither are fully implemented yet, but both are usable) Many configuration options Bash style completion (optional in Cmd mode, default in Emacs mode) Bash/zsh style interactive history search (CTRL-R) Emacs yank/kill ring PowerShell token based “word” movement and kill Undo/redo Automatic saving of history, including sharing history across live sessions “Menu” completion (somewhat like Intellisense, select completion with arrows) via Ctrl+Space Installation You will need PowerShellGet. »