Powershell
Core
Get-Help – Displays information about PowerShell commands and concepts
Get-Help Select-String
Get-Help Select-String -examples
This example displays the online version of the help article for the Format-Table cmdlet in your default web browser:
Get-Help Format-Table -Online
Downloads and installs the newest help files on your computer:
sudo Powershell.exe Update-Help
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-help
Get-History – Gets a list of the commands entered during the current session
Get-History [[-Id] <long[]>] [[-Count] <int>] [<CommonParameters>]
Get-History
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-history
Invoke-Command – Runs commands on local and remote computers
Invoke-Command -FilePath C:\scripts\test.ps1 -ComputerName Server01
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command
Grep equivalent
Get-WindowsCapability -Online | Select-Object Name | Select-String -Pattern 'SNMP'
Output format
Format-Custom
Format-Hex
Format-List
Format-Table
Format-Wide
Custom properties
Get-Volume | Select-Object -Property DriveLetter,FileSystemLabel,@{label="Size(GB)";expression={$_.size/1GB}}
Within the ScriptBlock, you can use the $_ variable to reference the current object in the pipeline.
Tasks
Get hostname
$env:COMPUTERNAME
Run a script without interferences
powershell.exe -ExecutionPolicy Bypass myscript.ps1
Get Powershell version
Get-Host | Select-Object Version
To create a blank file
New-Item -ItemType file example.txt
ni -i file example.txt
https://theitbros.com/run-powershell-script-on-remote-computer/