Practice
  • 🛤️TryHackMe Rooms
    • HackersVsHackers
    • Vulnnet - The End Game
    • Surfer
    • Corridor
    • Mustacchio
    • Wordpress: CVE-2021-29447
    • Bounty Hacker
    • Simple CTF
    • Agent Sudo
    • Lazy Admin
    • Ignite
    • Brooklynn 99
    • c4ptur3th3fl4g
    • Lian_Yu
    • Rabbit
    • Gallery
    • Overpass
    • Team
    • Easy Peasy
    • CmesS
    • Ultratech
    • Wonderland
    • Anonymous
    • GamingServer
    • Tomghost
    • ConvertMyVideo
    • DogCat
    • Blog
    • Git Happens
    • 0day
    • Road
    • Inferno
    • Opacity
    • Market Place
    • Valley CTF
    • Weasel
    • SafeZone
    • Blueprint
    • Fusion Corp
    • Quotient
    • Unbaked Pie
    • Kenobi
    • Steel Mountain
    • Alfred
    • Hack Park
    • Game Zone
    • Daily Bugle
    • Retro
    • Corp
    • Attacktive Directory
    • Vulnnet - Roasted
    • Vulnnet - Active
    • Vulnnet - Internal
    • Enterprise - Hard
    • Iron Corp - Hard
    • Ra - Hard
    • For Business Reasons
  • 📦HackTheBox
    • Linux Boxes
      • Lame
      • Shocker
      • Nibbles
      • Beep
      • Cronos
      • Nineveh
      • Sense
      • Solidstate
      • Node
      • Valentine
      • Poison
      • Sunday
      • Irked
      • FriendZone
      • Networked
      • Jarvis
      • Tabby
      • Mirai
      • Popcorn
    • Windows Boxes
      • Active
      • Forest
      • ChatterBox
      • Resolute
      • Intelligence
  • 🤖CTF's
    • CloudSEK CTFs
    • ACM Cyber - UCLA
  • ¯\_(ツ)_/¯
    • Interview Topics
  • 🪣BOF - OSCP
    • Basics
    • Spiking
    • FUZZing
    • Finding the Offset
    • Overwriting the EIP
    • Finding BAD Characters
    • Finding RIGHT Module
    • Generating Shellcode
  • 📛Active Directory
    • Basics
      • Managing AD Users
      • Managing AD Computers
      • Group Policies
      • Authentication Methods
      • Trees, Forests and Trusts
    • Enumeration Techniques
    • Initial Attack Vectors
    • Post Compromise Enumeration
    • Post Compromise Attacks
      • Token Impersonation - LM
      • Kerberoasting
      • cPassword / GPP Attack
      • URL File Attacks
      • PrintNightmare
      • Golden Ticket Attacks
      • ZeroLogon Attacks
    • Lateral Movement and Pivoting
      • File Transfers
      • Spawning Processes Remotely
      • Moving Laterally with WMI
      • Alternate Authentication Material
      • Abusing User's Behaviour
      • Port Forwarding
      • Maintaing Access
      • Pivoting
      • Cleaning Up
    • Other Resources
  • 🛡️Powershell Basics
    • Getting Started
      • Functions
  • 😁Others
    • API Security
    • Cloud Security
  • Enumeration
    • Local PrivEsc
    • Remoting
    • Persistence
    • Kerberos
Powered by GitBook
On this page
  • Operators in Powershell
  • Types in Powershell
  • Type Conversion
  • Arrays
  • Conditional Statements
  • Loop Statements
  1. Powershell Basics

Getting Started

PRACTICE ! PRACTICE ! PRACTICE !

In Powershell, Get-Help, Get-Command, Get-Alias are the most handful commands to ever exist

Aliases are the shorthand notes for the commandlets, it lets to identify the correct commandlet of the specified alias

Get-Alias iex

Provides help of the specified commandlet, if -Examples is specified the usage examples are also provided

Get-Help Get-ChildItem
Get-Help Get-ChildItem -Examples
help Get-Process

Lists the available commandlets with the sepecified noun and verb

Get-Command "Get-*"
Get-Command "*-Service"
Get-Command -CommandType Cmdlet -Name out*

Operators in Powershell

Basic Math Operations

3 + 3
3 * 4
4 - 3
"Hello" + " World"
"Hello" + 3
3 + "Hello" - Gives Error, as operations in powershell is carried out by priortizing the the left most variable's data type. In this case it tried to convert the "Hello" string into integer but failed !

Assignment Operators

$a = 10
$b = 10
$result = $a + $b
echo $result

$a *= 4         // $a = $a * 4

Comparison Operators

3 -eq 4
3 -ne 4
3 -le 4
"Hello powershell" -match "power"
"Hello powershell" -replace "power","shark"
1 -in (1,2,3)

Redirections

  • Similar to Linux Shell

Get-Location > C:\Temp\loc.txt
Get-Location >> C:\Temp\loc.txt
Get-Process none,explorer 2>&1

Advanced Operators

  • Logical ( -and, -or, -xor -not, !)

  • Split and Join (-split, -join)

  • Type Operators (-is, -isnot, -as)

(1 -le 3) -and (1 -ge 0) = True
(1 -le 3) -or (1 -ge 2)  = True
(1 -eq 1) -xor (2 -eq 2) = False

"Welcome to my home" -split " "
"Wel","Please" -join "come",""

3 -is "int"
"3" -is "string"
0x12 -is "int"
0x12 -is "string"

Types in Powershell

$value = "string" + 1
$value.GetType()

$str1 = "akash"
$str2 = 'akash'
$str1.GetType(),$str2.GetType()

"another string: $str1"        - returns akash
'another string: $str2'        - returns $str2

Type Conversion

$a = 3.2 + 3
$a.GetType()        - Returns Double 

[int]$a = 3.2 + 3
$a.GetType()        - Returns Int32

Arrays

  • Commands in powershell return an array of objects[]

$result = Get-ChildItem
$result.GetType()    - Returns Object[]

$array = 1,2,3,4,5
$array.length
$array[1]
$array[3]

Conditional Statements

if (1 -ge 0) {"One"} else {"Something"}
One

if (1 -ge 3) {"One"} else {"Something"}
Something

if ( ((Get-Process).HandleCount) -ge 40) {"Many processes"} else {"OK"}
Many processes
switch (1) { 1 {"one"} 2 {"two"} default {"Default"}}
one

switch (3) { 1 {"one"} 2 {"two"} default {"Default"}}
Default

Loop Statements

  • while() {}

  • do {} while()

  • do {} until()

  • for(;;) {}

  • foreach(in) {}

$count = 3
while ($count -ge 0)
{
"Iteration $count"
$count--
}
$process = Get-Process
foreach ($i in $process) {
$i.name
$i.path
}
  • ForEach-Object

  • Where-Object

Get-Process | ForEach-Object {$_.name}
Get-ChildItem C:\test | Where-Object ($_.name -match "txt"}
PreviousOther ResourcesNextFunctions

Last updated 1 year ago

🛡️