Windows Service
-
CMD
Elevate permission
Disk IO
robocopy
diskpart
Directory
-
CMD
-
dir /x
Displays the short names generated for
non-8.3
file names, which can be used to avoid spaces in paths. -
UNC paths are not supported
-
-
Powershell
cmd /c dir /x
Environment Variable
-
Windows environment variables
-
Display environment variable value
PowerShell
:$env:<VARIABLE_NAME>
, useTAB
key for auto complete.
-
Refresh environment variables, making changes take effect
PowerShell
: Ifchocolatey
is installed, userefreshenv
.
Powershell
-
Use the old-fashioned
CMD
promptcmd /c <CMD command>
-
The Help System
Get-Help / help <command-name>
-
Sends output to an interactive table in a separate window
Out-GridView
(opens in a new tab)Get-Service | Out-GridView
-
Paginate standard output
Get-Service | more
<SPACE>
: Next page<ENTER>
: Next lineq
: Quit
-
Transpose output of a table
Get-Service | Format-List
-
Prettify output as a table
-
Format-Table
(opens in a new tab)-AutoSize
: avoid truncation-GroupBy <column-name>
- Examples
Get-Service -Name win* | Format-Table -AutoSize -GroupBy status
-
-
Sort output
Sort-Object [-Descending]
-
Examples
-
Get-Process | Sort-Object id
-
-
-
Filter output
Where-Object
(opens in a new tab)-
Examples
-
Get-Service | Where-Object {$_.<column-name> -eq "<column-value>"}
-
-
-
-
Display all effective aliases
alias
or
Get-Alias
-
Create new aliases
New-Alias -Name <alias-name> -Value <alias-value>
-
-
Working with archives
-
Compression
-
Compress a directory that includes the root directory
Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft.zip
-
-
Extraction
-
Extract contents of an archive into a specified directory
Expand-Archive -LiteralPath 'C:\Archives\Draft[v1].zip' -DestinationPath C:\Reference
-
-
-
Search
-
Search file(s) by pattern
Get-Childitem –Path <PATH> -Include <FILE_PATTERN> -Exclude *.JPG,*.MP3,*.TMP -File -Recurse
-
Search file content (
grep
equivalent)
-
-
Clipboard interactions
-
Pipe stdin to clipboard (copy)
PS> $env:ComputerName | Set-Clipboard
-
Get clipboard content (paste)
-
Resources
-
-
Find the location of a command, equivalent to
which
inbash
Get-Command <command> -All
Networking
-
Excluded port range
Messages like
Ports are not available: listen tcp 0.0.0.0:<port>: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
could mean the specified port is being excluded instead of being used.Use
netsh interface ipv4 show excludedportrange protocol=tcp
, you will get:Protocol tcp Port Exclusion Ranges Start Port End Port ---------- -------- 1031 1130 1131 1230 1231 1330 1331 1430 1431 1530 1561 1660 2363 2462 2463 2562 2563 2662 2663 2762 2763 2862 2863 2962 5357 5357 50000 50099 * 55500 55599 * - Administered port exclusions.
Run
net stop winnat
andnet start winnat
to restartwinnat
service.Now the port should be available, but if you are disconnected, you need to reboot.
Run
netsh interface ipv4 show excludedportrange protocol=tcp
, your port is probably not excluded anymore.