Skip to content

Instantly share code, notes, and snippets.

@greglecki
Last active September 25, 2020 15:00
Show Gist options
  • Select an option

  • Save greglecki/b4696b1854dd8bf28ec0530487cf1cd0 to your computer and use it in GitHub Desktop.

Select an option

Save greglecki/b4696b1854dd8bf28ec0530487cf1cd0 to your computer and use it in GitHub Desktop.
PowerShell commands

PowerShell Basic

List all services

get-service

Filter to show only stopped services

get-service | where-object Status -eq 'Stopped'

Filter to show only stopped services - display only Name and Status

get-service | where-object Status -eq 'Stopped' | select-object Name, Status

save object in variable

$data = get-service | where-object Status -eq 'Stopped' | select-object Name, Status

Print variable

$data

Save to file - out-file

$data | out-file .\services.txt

Open in Notepad

notepad .\services.txt

Export to CSV - export-csv

$data | export-csv .\services.csv

Show content - get-content

get-content .\services.csv | more

Check PS version

$PSVersionTable

Check number of services

(get-service).count

List commands - filter by name

get-command -Name SEARCH_TERM

Get info about specific verb (example: Set)

get-verb -Verb Set | format-list

Formatting

format-list, format-table

List aliases

get-alias

Search installed commande

get-command get-command -Verb Get -Noun DNS get-command -Name FIre -CommandType Function

Help how to use command; Search PowerShell commands

get-help get-help -Name Get-Command -Detailed man -Name Get-Command -Detailed get-help -Name DNS help get-service help get-service -Examples help get-service -Full

Get properties and methods of objects

get-member get-service | get-member

Creates a record of all or partsof a PowerShell session to a text file

start-transcript start-transcript -path .\transcript1.txt -append

Stop transcript

stop-transcript

Accessing current object in the pipeline $_

where-object {$_.property -eq 'xxx'}

Gets the files and folders in a file system drive

get-childitem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment