🕶️
VICEINTELPRO
GitHub: HorrorClause
  • In Tenebris Videmus
  • 🚩CTFs
    • 💾Hack the Box
      • 🏫Academy
        • Command Injection Assessment
        • XSS Assessment
        • Web Attacks Assessment
    • Try Hack Me
      • In Progress
  • 📖Documents
  • 👨‍🏫HOW-TOs
    • Obisidian How-To
    • Setup Mandiant FLARE VM
  • 📑Security Fundamentals
    • Security Controls
      • Physical Security
      • Endpoint Security
      • Email Security
      • Network Security
      • AAA Controls
    • Networking 101
      • OSI Model
      • Network Fundamentals
      • Network Devices
      • Network Tools
      • Protocols and Ports
    • 👨‍💼Management Principles
      • Risk
      • Policies and Procedures
      • Compliance and Frameworks
      • Change and Patch Management
  • 🛡️Security Concepts
    • ⚠️Risk Assessment Models
      • DREAD Risk Assessment Model
      • STRIDE Threat Model
      • Common Vulnerability Scoring System (CVSS)
    • Pentesting
      • Common Terms
      • AV Identification-Evasion
      • Introduction to Payloads
      • Automating Payloads & Delivery with Metasploit
      • Shells Jack Us In, Payloads Deliver Us Shells
      • Web Shells
      • Pentesting Overview
      • Penetration Testing Process
    • 🐛Vulnerability Assessment
      • Common Vulnerabilities and Exposures (CVE)
      • Common Vulnerability Scoring System (CVSS)
      • Assessment Standards
      • Vulnerability Assessment
      • Vulnerability Scanning
      • Reporting
      • 🎯Nessus
        • Getting Started with Nessus
        • Nessus Scan
        • Working with Nessus Scan Output
        • Advanced Settings
        • Scanning Issues
      • 🦴OpenVAS (Greenbone)
        • Getting Started with OpenVAS
        • OpenVAS
        • Exporting Results
    • Passwords
      • Password Managers
      • Password Policies
      • Password Security Fundamentals
    • Frameworks
    • GRC
    • Logon Types
    • What is Dev-Null ?
  • ⚔️Offensive Security
    • OSINT
      • OSINT - Websites
      • Google Dorks
    • 🔫Attacking Common Services
      • The Concept of Attacks
      • Interacting with Common Services
      • Finding Sensitive Information
      • Attacking DNS
      • Attacking Email Services
      • Attacking FTP
      • Attacking RDP
      • Attacking SMB
      • Attacking SQL Databases
      • Cheat Sheet - Attacking Common Services
      • Service Misconfigurations
    • 🔪Attacking Web Apps with Ffuf
      • Web Fuzzing
      • Directory Fuzzing
      • Page Fuzzing
      • Recursive Fuzzing
      • DNS Records
      • Sub-domain Fuzzing
      • Vhost Fuzzing
      • Filtering Results
      • Parameter Fuzzing - GET
      • Parameter Fuzzing - POST
      • Value Fuzzing
    • ☁️Cloud
      • AWS
        • AWS S3 Buckets
    • 💉Command Injection
      • Command Injection Cheat Sheet
      • Intro to Command Injections
      • Detection
      • Injecting Commands
      • Other Injection Operators
      • Identifying Filters
      • Bypassing Space Filters
      • Bypassing Other Blacklisted Characters
      • Bypassing Blacklisted Commands
      • Advanced Command Obfuscation
      • Evasion Tools
      • Command Injection Prevention
    • Containers
      • Docker
    • ❌Cross-Site Scripting (XSS)
      • Introduction to XSS
      • Stored XSS
      • Reflected XSS
      • DOM XSS
      • XSS Discovery
      • Defacing
      • Phishing
      • Session Hijacking
      • XSS Prevention
    • Directory Busting
      • DirB
      • DirBuster
      • Ffuf
      • Gobuster
    • 🅰️DNS
      • DNSRecon
      • Fierce
    • File Inclusion
      • Local File Inclusion Cheatsheet
      • Intro to File Inclusion
      • Local File Inclusion (LFI)
      • Basic Bypass
      • PHP Filters
      • PHP Wrappers
      • Remote File Inclusion (RFI)
      • LFI and File Uploads
      • Log Poisoning
      • Automated Scanning
      • File Inclusion Prevention
    • File Transfers
      • Transferring Files
      • File Transfer - Quick Commands
      • Living off the Land
      • Windows File Transfer Methods
      • Linux File Transfer Methods
      • Catching Files over HTTP(S)
      • Transferring Files with Code
      • Miscellaneous File Transfer Methods
      • Protected File Transfers
      • Mounting Encrypted VHD Drives
      • Mounting VHD in Kali
      • File Transfer Detection
    • File Upload Attacks
      • File Upload Cheatsheet
      • Absent Validation
      • Upload Exploitation
      • Client-Side Validation
      • Blacklist Filters
      • Whitelist Filters
      • Type Filters
      • Limited File Uploads
      • Other Upload Attacks
      • Preventing File Upload Vulnerabilities
    • 👣Footprinting
      • Linux Remote Management Protocols
      • Windows Remote Management Protocols
      • Enumeration
        • Enumeration Methodology
        • 🖥️Host Based
          • Quick Commands
          • DNS
          • FTP
          • IMAP-POP3
          • IPMI
          • MSSQL
          • MySQL
          • NFS
          • Oracle TNS
          • SMB
  • Powershell
    • Powershell CheatSheet
  • Python
    • Map
    • Anonymous Functions
    • Recursion
      • ZipMap
      • Nested Sum
      • Recursion on a Tree
      • Count Nested Levels
      • Longest Word
    • Function Transformations
      • More Transformations
      • Why Transform?
    • Closures
    • Currying
    • Decorators
    • Sum Types
    • Enums
    • Match
    • Regex
  • Kusto (KQL)
    • SQL and KQL Comparison
    • Using the Where and Sort Operators
    • KQL Queries
  • HTML
  • Insecure File Uploads
Powered by GitBook
On this page
  • What are the different ways I can run PowerShell as an Administrator?
  • How to Run cmdlets
  • How to Run PowerShell Scripts
  • Overlap with Windows Commands
  • Here are some commands that are common to PowerShell and Windows:
  • Backing Up an SQL Database with PowerShell
  • The Essential PowerShell Commands
  • Get-Help
  • Get-Service
  • ConvertTo-HTML
  • Export-CSV (and Get-Service)
  • Get-Process
  • Get-EventLog
  • Stop-Process
  • PowerShell Commands List
  1. Powershell

Powershell CheatSheet

Helpful walkthrough and tips for using Powershell, sourced from the below linked site

PreviousPowershellNextPython

Last updated 3 months ago

Source Site:

What are the different ways I can run PowerShell as an Administrator?

  1. Press WIN + R, type in powershell, press Ctrl+Shift+Enter. Click OK to run as Administrator.

  2. Type powershell into the Taskbar search field. Select Run as Administrator from the list of options in the right panel of the results list.

  3. Open the Command Prompt, type powershell, and press Enter. Type start-process PowerShell -verb runas and press Enter.

  4. *Also in the Command Prompt, type runas /netonly /user:RemoteDomain\Administrator powershell (substitute a URL or hostname for RemoteDomain)

*A note on option 4 in this list:

The /netonly option of runas applies a user account to remote targets. So, in this case, you want to run PowerShell as Administrator on a computer that is identified by RemoteDomain. The Administrator account is active on that remote device and not on the local machine, so, when prompted, give the password for the Administrator account when prompted, not the password for the Administrator account on the local computer.

How to Run cmdlets

In a nutshell, a cmdlet is a single-function command. You input cmdlets into the command line just as you would with a traditional command or utility. Cmdlets are the main way to interact with the CLI

In PowerShell, most cmdlets are written in C# and comprised of instructions designed to perform a function that returns a .NET object.

Over 200 cmdlets can be used in PowerShell. Windows PowerShell command prompt isn’t case-sensitive, so these commands can be typed in either upper or lower case. The main cmdlets are listed below:

  • Get-Location – Get the current directory

  • Set-Location – Get the current directory

  • Move-item – Move a file to a new location

  • Copy-item – Copy a file to a new location

  • Rename – item Rename an existing file

  • New-item – Create a new file

For a full list of commands available to you, use the Get-Command cmdlet. In the command line you would enter the following:

PS C:\> Get-Command

It is important to note that Microsoft restricts users from using custom PowerShell cmdlets in its default settings. In order to use PowerShell cmdlets, you need to change the ExecutionPolicy from Restricted to RemoteSigned. Remote Signed will allow you to run your own scripts but will stop unsigned scripts from other users.

To change your Execution policy, type in the following PowerShell command:

PS C:\>   Set-ExecutionPolicy

To change to RemoteSigned, type the following command:

PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Make sure you’re on an Administrator account so that you have permission to set a new execution policy.

How to Run PowerShell Scripts

Script-based processes and commands are part of the foundation of PowerShell’s versatility. In PowerShell, a script is essentially a text file with a ps1 extension in its filename. To create a new script you can simply open the Windows notepad, type your commands, and save with ‘.ps1’ at the end of the name.

To run a script, enter its folder and filename into the PowerShell window:

PS c:\powershell\mynewscript.ps1

Once you’ve done this, your selected script will run.

Overlap with Windows Commands

When you’re new to PowerShell it can feel overwhelming to try and learn a whole new library of commands. However, what most new users don’t realize is that the syntax used on Windows command-line overlaps with PowerShell. This is made easier by the fact that PowerShell isn’t case sensitive.

Much like Command Prompt, on PowerShell the cd command still changes directories, and dir still provides a list of files within the selected folder. As such, it’s important to remember you aren’t necessarily starting from scratch. Taking this on board will help to decrease the learning curve you face when using PowerShell and decrease the number of new commands that you have to learn.

That being said, it is important to note that these aren’t considered complete PowerShell commands so much as they are aliases (PowerShell’s name for Windows command prompt commands). So even though you can try some of Command Prompt’s commands in PowerShell, you should learn as much as you can about the new ones. Nonetheless, Command Prompt experience can definitely help new users to come to grips with PowerShell and hit the ground running.

Here are some commands that are common to PowerShell and Windows:

  • cd: Change Directory. This command is used to change the current working directory. In PowerShell, Set-Location can be used as well.

  • cls: Clear Screen. This command clears the screen of the console. In PowerShell, Clear-Host or its alias cls can be used.

  • dir: Directory. This command lists the files and subdirectories in the directory. In PowerShell, Get-ChildItem can be used as well.

  • echo: This command prints text to the console. In PowerShell, Write-Output can be used as well.

  • copy: This command copies files. In PowerShell, Copy-Item can be used as well.

  • del: Delete. This command deletes one or more files. In PowerShell, Remove-Item can be used as well.

  • move: This command moves files from one location to another. In PowerShell, Move-Item can be used as well.

  • type: This command displays the contents of a text file. In PowerShell, Get-Content can be used as well.

  • find: This command searches for a text string in a file. In PowerShell, Select-String can be used as well.

  • exit: This command closes the command prompt or terminal window. It works the same in both Command Prompt and PowerShell.

Backing Up an SQL Database with PowerShell

Many people use PowerShell to back up SQL databases. The command-line interface can conduct full database backups, file backups, and transaction log backups. There are many ways to backup a database in PowerShell, but one of the simplest is to use the Backup-SqlDatabase command. For example:

PS C:\> Backup-SqlDatabase -ServerINstance “Computer\Instance” -Database “Databasecentral”

This will create a database backup of a database with the name ‘Databasecentral’ (or the name of your chosen database’.

To back up a transaction log, you would input:

PS C:\> Backup-SqlDatabase -ServerInstance “Computer\Instance”  -Database “Databasecentral” -BackupAction Log

This will create a transaction log of the selected database.

The Essential PowerShell Commands

Using aliases will only get you so far on PowerShell, so it’s important to commit to learning everything you can about PowerShell’s native commands. We touched on some of these above, but we’re going to break down the main ones in much more detail below.

Get-Help

This command should be at the very top of any new user’s list when it comes to PowerShell. The Get-Help command can be used to literally get help with any other PowerShell command. For example, if you know the name of a command, but you don’t know what it does or how to use it, the Get-Help command provides the full command syntax.

For example, if you wanted to see how Get-Process works, you would type:

PS C:\> Get-Help -Name Get-Process
PS C:\> Set-ExecutionPolicy

As touched on earlier in this guide, Microsoft has a restricted execution policy that prevents scripting on PowerShell unless you change it. When setting the execution policy, you have four options to choose from:

  • Restricted – The default execution policy that stops scripts from running.

  • All Signed – Will run scripts if they are signed by a trusted publisher

  • Remote Signed – Allows scripts to run which have been created locally

  • Unrestricted – A policy with no restrictions on running scripts

PS C:\> Get-ExecutionPolicy

If you’re using PowerShell, you may not always work on a server that you’re familiar with. Running the command Get-Execution Policy will allow you to see which policy is active on the server before running a new script. If you then see the server in question operating under a restricted policy, you can then implement the Set-ExecutionPolicy command to change it.

Get-Service

One of the most important commands is Get-Service, which provides the user with a list of all services installed on the system, both running and stopped. This cmdlet can be directed by using specific service names or objects.

For example, if you were to type PS C:\> Get-Service, you would be shown a list of all services on your computer, their statuses, and display names.

To use this command to retrieve specific services, type: PS C:\ Get-Service “WMI*” to retrieve all services that begin with WMI.

If you wanted to restrict output to active services on your computer, input the following command:

PS C:\ Get-Service | Where-Object {$_.Status -eq “Running”}

ConvertTo-HTML

When using PowerShell, you might want to generate a report about the information you’ve seen. One of the best ways to do this is by using the ConvertTo-HTML command. This cmdlet allows you to build reports with tables and color, which can help to visualize complex data. Simply choose an object and add it to the command.

For example, you could type:

Get-PSDrive | ConvertTo-Html

This returns a mass of information, so it’s a good idea to limit it to a file with the Out-File command. A better alternative command is:

Get-PSD Drive | ConvertTo-Html | Out-File -FilePath PSDrives.html

This will then generate an HTML file in table form. For example:

You can then add your own colors and borders to refine its presentation.

Export-CSV (and Get-Service)

No less important for increasing visibility is the Export-CSV command. It allows you to export PowerShell data into a CSV file. Essentially, this command creates a CSV file compiling all of the objects you’ve selected in PowerShell. Every object has its own line or row within the CSV file. This command is primarily used to create spreadsheets and share data with external programs.

To use this command, you would type:

PS C:\> Get-Service | Export-CSV c:\service.csv

It’s important to remember not to format objects before running the Export-CSV command. This is because formatting objects results in only the formatted properties being placed into the CSV file rather than the original objects themselves. In the event that you want to send specific properties of an object to a CSV file, you would use the Select-Object cmdlet.

To use the Select-Object cmdlet, type:

PS C:\> Get-Service | Select-Object Name, Status | Export-CSV c:\Service.csv

Get-Process

If you want to view all processes currently running on your system, the Get-Process command is very important. To get a list of all active processes on your computer, type:

PS C:\ Get-Process

Notice that if you don’t specify any parameters, you’ll get a breakdown of every active process on your computer. To pick a specific process, narrow the results down by process name or process ID and combine that with the Format-List cmdlet, which displays all available properties. For example:

PS C:\ Get-Process windowrd, explorer | Format-List *

This provides you with comprehensive oversight of all active processes.

Get-EventLog

If you ever want to access your computer’s event logs (or logs on remote computers) while using PowerShell, then you’re going to need the Get-EventLog command. This cmdlet only works on classic event logs, so you’ll need the Get-WinEvent command for logs later than Windows Vista.

To run the event log command, type:

PS C:\> Get-EventLog -List

This will show all event logs on your computer.

One of the most common reasons users look at event logs is to see errors. If you want to see error events in your log, simply type:

PS C:\> Get-EventLog -LogName System -EntryType Error

If you want to get event logs from multiple computers, specify which devices you want to view (listed below as “Server1” and “Server2”). For example:

PS C:\> Get-EventLog - LogName “Windows PowerShell” -ComputerName “local computer”, “Server1”, “Server2”.
Parameters you can use to search event logs include:

After

User specifies a date and time and the cmdlet will locate events that occurred after

AsBaseObject

Provides a System.Diagnostics.EventLogEntry for each event

AsString

Returns the output as strings

Before

User specifies a date and time and the cmdlet will locate events that occurred before

ComputerName

Used to refer to a remote computer

EntryType

Specifies the entry type of events (Error, Failure Audit, Success Audit, Information, Warning)

Index

Specifies index values the cmdlet finds events from

List

Provides a list of event logs

UserName

Specifies usernames associated with a given event

Stop-Process

When using PowerShell, it’s not uncommon to experience a process freezing up. Whenever this happens, you can use Get-Process to retrieve the name of the process experiencing difficulties and then stop it with the Stop-Process command.

Generally, you terminate a process by its name. For example:

PS C:\> Stop-Process -Name “notepad”

In this example, the user has terminated Notepad by using the Stop-Process command.

PowerShell Commands List

Here are 25 basic PowerShell commands:

Command name
Alias
Description

Set-Location

cd, chdir, sl

Sets the current working location to a specified location.

Get-Content

cat, gc, type

Gets the content of the item at the specified location.

Add-Content

ac

Adds content to the specified items, such as adding words to a file.

Set-Content

sc

Writes or replaces the content in an item with new content.

Copy-Item

copy, cp, cpi

Copies an item from one location to another.

Remove-Item

del, erase, rd, ri, rm, rmdir

Deletes the specified items.

Move-Item

mi, move, mv

Moves an item from one location to another.

Set-Item

si

Changes the value of an item to the value specified in the command.

New-Item

ni

Creates a new item.

Start-Job

sajb

Starts a Windows PowerShell background job.

Compare-Object

compare, dif

Compares two sets of objects.

Group-Object

group

Groups objects that contain the same value for specified properties.

Invoke-WebRequest

curl, iwr, wget

Gets content from a web page on the Internet.

Measure-Object

measure

Calculates the numeric properties of objects, and the characters, words, and lines in string objects, such as files …

Resolve-Path

rvpa

Resolves the wildcard characters in a path, and displays the path contents.

Resume-Job

rujb

Restarts a suspended job

Set-Variable

set, sv

Sets the value of a variable. Creates the variable if one with the requested name does not exist.

Show-Command

shcm

Creates Windows PowerShell commands in a graphical command window.

Sort-Object

sort

Sorts objects by property values.

Start-Service

sasv

Starts one or more stopped services.

Start-Process

saps, start

Starts one or more processes on the local computer.

Suspend-Job

sujb

Temporarily stops workflow jobs.

Wait-Job

wjb

Suppresses the command prompt until one or all of the Windows PowerShell background jobs running in the session are …

Where-Object

?, where

Selects objects from a collection based on their property values.

Write-Output

echo, write

Sends the specified objects to the next command in the pipeline. If the command is the last command in the pipeline,…

Looking to create your own PowerShell scripts? Nearly 5k students have taken .

this Udemy course on Advanced Scripting with PowerShell
PowerShell CheatSheet