Powershell For Beginners : Introduction to Windows powershell

Powershell is a scripting and automation platform for Miscrosoft platform which is built on top of .Net framework. it is useful for system tasks automation, system administration etc. on windows systems. Powershell is basically a replacement of Command Prompt (cmd.exe) on windows based systems.

Powershell borrowed a lot of functionality and commands from the Linux environment including many Linux commands. For example the ability to pipe commands and link commands into a script.

The cmdlets or commandlets are single commands that accomplish (sometimes) more complex tasks similer to functions. cmdlets follow verb-noun pattern, for example “get-help“. This help users understand the purpose of the commands. Verbs include New, Set, Get, Add and Copy. Microsoft has a documented list of approved verbs and their intended uses to help maintain consistency throughout the platform. When placed together with nouns, you get cmdlets such as:

  • Get-Help
  • Get-Process
  • Write-Output

Opening Powershell window : Goto search bar and type powershell and then you have powershell interpreter.

Now lets see some examples :

  • Get-Help : Get-help cmdlets shows the help page about a command or cmdlet. It is basically works like man command of linux terminal.

Get-Help <cmdlet-name>

Example :

Get-Help write-Output

The write-Output command is similar to echo command. It has also alias for echo, write.

  • Get-Process : Lists all the processes.

Get-Process

Some Resources for Cmdlets :

PowerShell Integrated Scripting Environment :

Windows (7, 8, 10..) has an integrated IDE pre-installed called Powershell ISE to write and run Powershell script. It also has a help tab which lists all the cmdlets with details. To open Powershell ISE type “Powershell ISE” on search bar and open the app.

The example use of powershell ISE

Running a Powershell script :

To run a powershell script right click on script and click “Run with Powershell”.

Some Common Commands/Cmdlets used in Powershell :

CommandletsaliasDescription
Get-Locationpwd,glshows current working directory
Get-Helphelp,manShow help page of commands
get-Contentcat,type,gcGet the content of a file
Get-CommandgcmList all the commands
Get-Childitemls,dir,gcilist all contents in directory
Clear-Hostclear,clsclear screen
Copy-Itemcopy,cp,cpicopy file/directories
Move-Itemmi,move,mvmove files/directories
Remove-Itemri,del,rd,rm,rmdirremove file/directories
rename-Itemrni,ren,mvrename file/directories
Set-Locationcd,chdir,slchange directory
Push-LocationpushdPush current directory location on stack
Pop-LocationpopdChange directory to currently pushed location
Tee-ObjectteePipe standard input into file and standard output stream
Write-Objectecho,writeprint string, variables to standard output
Get-Processps,gpslist all the processes
Stop-Processkill,sppsstop a running process
Select-StringslsPrint line matching a pattern(similar to grep)
Set-Variablesv,setSet the value of a variable/create a variable
Invoke-WebRequestiwr,curl,wgetGets content from web page on the internet

Now in next blogposts we are going to look at the basic powershell scripting concepts and methods.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.