Learning PowerShell — Let’s Do It Together — Part 1

Kamran Saifullah
6 min readFeb 8, 2020

Powershell comes pre-installed with Microsoft Windows and it is used for task automation and configuration management framework. On the other hand it works directly with the memory and by so it becomes hard for the companies to detect powershell commands/scripts being run in the network although the networks can be monitored to check if particular cmdlets are being run in order to prevent the attacks.

Powershell allows us to use commands and also allows us to write scripts to automate our work. These commands are written in .NET Classes which implement a particular operation. So let’s get started with learning Powershell.

The power of the PowerShell is that it provides access to almost everything on the Windows Operating Systems including the WMI (Windows Management Instrumentation), COM Objects, Windows API, Windows Registry and many more. As it is tightly integrated with windows systems and also is trusted by the system administrators for their job to be done.

Getting Started

The first and the foremost thing is to open up PowerShell terminal. New windows terminal has it by default. If you don’t have the new Windows Terminal you can simply search for “Powershell” and open the Powershell app!

Once you have opened. You should see the terminal which looks like as above meanwhile we will run the command as above to check the Powershell version.

$PSVersionTable

We can narrows down the search with the PSVersionTable by using the following commands.

We can also check for the version by using the “Get-Host or host” command.

We can also only select the option which we require by using the following command.

Get-Host | Select-Object Version

Else we can use the more simplified version.

(Get-Host).Version

There are lots and lots of cmdlets or command-lets available within the powershell. We can see all of them by issuing the following command.

Get-Command -CommandType cmdlet

You will find that there are too many cmdlets and the screen keeps on scrolling. We can limit this and can search for the exact number of cmdlets which are available on our system. This can be done by using the following command.

Get-Command -CommandType cmdlet | measure

The measure command measure the total number of cmdlets as an integer.

In this case we have 628 cmdlets available. Similarly we can look for aliases, functions as well!

The most important thing while someone is trying to learn the command/scripts or programming language is to check for the help system. Powershell has built-in help system. The help system can be utilized by using the above command.

Get-Help

There are different examples of Get-Help at the end of this section.

We can check how a particular cmdlet will work by using the Get-Help options. Let’s check what can be done by using the “dir” command.

We can see that this command get’s the child items in the current directory. The other command which can be used is “Get-ChildItem or also “ls” command which is used in *nix based systems.

Similarly there are many aliases which have comes built-in with the PowerShell. Those can be found by using “Get-Alias” command.

We can find bunch of aliases like “clear, cls” commands which are used to clear the screen. Similarly “ls, dir” which are used to list the current directory items. We can also measure the total amount of aliases available.

For the time being we have 158 aliases configured.

Help Data for different commands is sometimes not available. What we can do is that we can issue “Update-Help” command in order to download all the help manuals for all the commands or for the commands of which the help manuals were not downloaded before.

but it has to be made sure, when we are using the Powershell terminal it should have the Administrator Privileges. Meanwhile if we want to see the help section online we can use the following command which will redirect us to a specific page on which the details of the commands are given.

Get-Help Get-Command -Online

Similarly when we are using the cmdlets in PowerShell. They do support different parameters. It’s obvious that we can not learn/remember all the parameters but what we can do is that we can narrow down our search in order to look for the parameter allowed/used by the command.

Get-Help Get-Command -Parameter *

What we did here is that we utilized the PowerShell help in order to look at the manual for Get-Command cmdlet and then we told the Get-Help to return only the parameters followed by a wildcard (*) which means all.

On submitting the command we have only received the parameters allowed to be supplied with this command.

Let’s get one step ahead. Let’s try to do some searching in the cmdlets to only receive the cmdlets which has “process” somewhere in their names.

Get-Command -CommandType cmdlet -Name *process*

We can see that on utilizing this command we have only received the cmdlets which can have anything in the beginning and anything in the end but inside there should be a string “process”. In this case we have 11 cmdlets which has to do something with the Windows Processes.

We can list the Windows Processes by using the command “Get-Process” cmdlet.

Similar to processes we can also list the services running on the system by using the “Get-Service” cmdlet.

We can also start a process. Let’s suppose that we are working on a terminal and we don’t want to open up the notepad by using the GUI. We can simply use the below command to open up a notepad.

Start-Process notepad.exe

Now let’s check if the process is actually running by using the above command.

Get-Process -Name notepad.exe

Indeed the process is running with ID - 12784.

Similarly we can also stop this process by issuing the following command.

Stop-Process -Id 12784

Now we can see that there is no process with the name of “Notepad”.

On the other hand, we can also look for the HotFixes which have been applied by using the above command.

Get-Hotfix

Similarly, there are hundreds of other commands as well. We will work more on the PowerShell in our next article!

--

--

Kamran Saifullah

Malware/RE/Firmware Analysis, App Sec/Off Sec, VAPT, Phishing Simulations/SE | Risk Management, IS Governance, Audits, ISO 27001 LI