What is Windows Powershell?

What is Windows Powershell?

What is Windows Powershell?- The Linux operating system has long offered more power and flexibility to its administrators through shell scripting. However, Microsoft Windows lacked this flexibility, because of the limited capabilities of the command prompt. To overcome this limitation, Microsoft introduced PowerShell to efficiently automate tasks and manage configurations. It is built on top of the .NET Framework and provides complete access to COM and WMI.

What is its application in hacking? If you are able to compromise a target system running Windows operating system, then using PowerShell, you can do many useful tasks.

The PowerShell Integrated Scripting Environment

PowerShell offers the Integrated Scripting Environment (ISE) which can be used to fire commands at runtime as well as develop and test new PowerShell scripts.

To access the PowerShell ISE, press the Windows key + R and enter powershell_ise.exe .. You will then see the screen shown in Figure.

In the upper-left pane, you can write new scripts, in the lower-left pane you can see the results after executing your scripts/commands, and on the right you can see all the default commands available in PowerShell.

Logic Building

Every programming language has basic constructs and logical decision-makers that are building blocks of a program. These include variables, functions, and decision-makers. The following sub-sections introduce the basic constructs in Windows PowerShell.


Variables are basic data structures to hold values. For example:
PS C:\Users\Sagar> $var = “Hello World”
PS C:\Users\Sagar> echo $var
Hello World
PS C:\Users\Sagar>

In this example we declared a new variable called $var , assigned the string value “Hello World” to it, and then printed the value the variable $var contains.

If Else Decision Making

The keywords If and Else are used for simple condition checking. If a condition is TRUE, then some action is performed; else (if it’s FALSE), then some other action is performed. For example:

PS C:\Users\Sagar> $value = 4
PS C:\Users\Sagar> If ($value -gt 0) {“The number is bigger than Zero”} Else {“The number is
less than Zero”}
The number is bigger than Zero
PS C:\Users\Sagar> $value = -1
PS C:\Users\Sagar> If ($value -gt 0) {“The number is bigger than Zero”} Else {“The number is
less than Zero”}
The number is less than Zero

The above simple code checks whether the number in the variable $Value is greater than or less than zero. The script is simple and trivial to understand.

For Loops

A FOR loop is a simple control flow statement that is commonly used to perform a task repetitively using iterations:
PS C:\Users\Sagar> for ($i=1; $i -le 10; $i++){$j=$i*2; Write-Host $j}

In this example, the first line of code uses a FOR loop to print a multiplication table of 2. It iterates from values 1 to 10, and for each iteration it multiplies the value in $i by 2, stores it in the variable $j and prints the value in $j . The Write-Host cmdlet is used to print output to the user’s screen . Now that we have seen how iterative tasks can be done using a FOR loop, let’s see how to combine two or more tasks using pipes.


Using pipes is an effective way of passing the output of one command as an input to another command. The pipe is denoted by the symbol | (a vertical line).

For example, the following code first executes the ls command, which lists the contents of the current working directory. Then, using the pipe (|), we pass the output as input to another command, Select-String with the parameter paros . This will display output only if a directory or file named paros is present in the current directory.

PS C:\Users\Sagar> ls | Select-String Paros

File-Handling Functions

File-handling functions are those that allow creation or deletion of files or directories on the system. These functions could be effectively used to create or remove multiple files or directories based on specified criteria.

Create a New File or Directory

Cmdlet used: New-Item .
Usage: To create a new directory, enter

New-Item C:\Powershell -ItemType directory
This will create a new directory called Powershell in the C drive. To create a new file, enter –

New-Item C:\Temp.txt -ItemType file
This will create a new file called Temp.txt in the C drive.

Delete a File or Directory

Cmdlet used: Remove-Item .
Usage: –
To delete an existing file, enter

Remove-Item C:\Temp.txt

This will delete a file named Temp.txt in from the C drive. To Delete all contents in a directory recursively, enter

Remove-Item C:\Powershell* -Recurse

This will forcefully delete all files and folders within the Powershell folder located on the C drive.

Copy Files

Cmdlet used: Copy-Item .

Copy-Item C:\Temp.txt D:\

This will copy the file Temp.txt from the C drive to the D drive.

Check File Properties

Cmdlet used: Get-ItemProperty

Get-ItemProperty C:\Temp.txt

This will display only the basic properties of the file Temp.txt . To view its advanced properties, enter

Get-ItemProperty C:\Temp.txt | Format-List -Property * -Force

This will list detailed metadata for the file Temp.txt located on drive.C

Windows Powershell Command Click Here

If you got any problem or need some more information you can comment below we will help you soon. To learn more about Hacking you can check more.

Related posts

Leave a Comment