Powershell Basics

About

This is a pocket guide to PowerShell for penetration testers. Advanced users will get nothing out of this.

Variables

Setting Variables:

$a = get-process

Retrieving values:

$a <enter>

Conditionals

Put conditionals inside {}

Symbol
PowerShell

<

-lt

>

-gt

<=

-le

>=

-ge

==

-eq

!=

-nq

Match String

-like

You can use ? to represent the output of the last command:

Loops

Print all elements in $a:

Execute a command returned by the loop use &:

Assign var $x to each elm:

General Tips

Create a list split by a delim

Get current powershell version:

Run older version of powershell:

Execution Policy

Execution policy is not a security protection. It is very easily bypassed. You can run PowerShell with the -noprofile to do so. You can also change the execution policy using:

Bypass Execution policy when running script

Get Execution policy

Set Execution policy

Download and Run:

Linux to PowerShell

Cat: Get-Content

Grep: -Select-String -pattern "password"

Last updated