Getting started with Powershell

So, now we know what is powershell, command-lets and modules. Hope you have played around with Get commands. In this blog we'll see how to install powershell and try to understand its console. We'll also discuss few shortcut keys to improve and ease out our work.

Installing Powershell



Windows Powershell is by-default installed on all Windows machines, starting from Windows 7 to Windows 2019. If you want to install Powershell 6 then install Powershell core instead of Windows powershell. For more info click on Installing Powershell 6.

How to find Powershell if installed in your machine or not?
Go-to left corner of your Windows server(2012, 2016 and 2019)/desktop(8 and 10), and click on search button and type Powershell or Press Windows Icon from your keyboard and then type Powershell, in any of the ways you'll get powershell tool.

If you are using windows 7 or windows 2008 machines then you may click on Start button and then search for Powershell keyword, this will show you normal powershell and its ISE as well.

For more ways to search Powershell refer to Ways to Launch PowerShell ".

When you try to search Powershell in your windows machine you'll get a (x86) version as well, which is used in 32bit architect, however here we're going to use 64bit powershell. Checkout which version of windows you are running.

Always launch powershell in administrator mode, as this enhances the liberation of work in powershell, else you'll many times get access denied, red texts in your powershell console.

After installing powershell and launching it, lets try to understand what's in its console and how does it look like.

Understanding Powershell Console

There are two ways to open powershell:

1. Normal Powershell console:  When you try to run normal Powershell.exe, a blue colored console appears on your screen and here you can execute the scripts or type single liner commands and execute them. In this console you can check the output as well. If you want to write a script, then use the second way.

Normal Powershell console.
2. Powershell ISE: Script writers generally use ISE (Integrated Script Environment) to do scripting. It's always recommended to run Powershell ISE in administrative mode as this gives you enough access to run scripts without filling up your console with red errors. ISE provides you Intelligent feature which helps to complete your command-lets. Suppose you are willing to run a get-service, you need to type Get- and rest intellisense will give you dropped down options to complete your cmdlt. As you go on completing your cmdlt intellisense provides you accurate cmdlts, if you get your command-let in-between just press TAB key from your key board and your cmdlt would auto-completed. In case you are not able to view your intellisense you may also use keyboard combination ctrl+space this will also show you the cmdlts.

Powershell ISE console.

Lets discuss the above screenshot in details.

Script Pane: Script pane is a white empty area where you can write your own script/code and can execute it from there only. It consists of numbers which shows the line number of the code/script. This script pane is called as work space.

Screenshot of work space where all scripts are written and executed. The output of the executed file is shown in output console.

Console Pane: In console pane, we can see the output of the script. We can also execute .ps1 files from here as well.

Screenshot of Output console.



Toolbar: Toolbar consists of list of icons which helps to execute/copy/cut/paste/save your scripts.

Screenshot of the Powershell ISE tool bar.

Below are the default icons on PowerShell ISE Toolbar
  • Create New (ctrl+N): This icon is used to create new page for scripting in the powershell ISE.
    Screenshot of New Icon
  • Open Folder (ctrl+O): You can open pre-existing script from your computer. Once you click this icon you can navigate/browse to the path/folder where the script is kept.
    Screenshot of Open Folder Icon
  • Save (ctrl+S): You can save your script by clicking this icon, or you can use ctrl+s to save your script.
Screenshot of Save button.
  • Copy (ctrl+C): You can copy script or any text from the script by selecting the script or can use ctrl+c key combination.
Screenshot of Copy button.
  • Paste (ctrl+P): You can paste the script from anywhere to the script pane in powershell. You can even use ctrl+p key combination to paste the script.
Screenshot of paste button.
  • Clear Console: To clear off the output console you can use Clear console button. Even you can type Clear-Host or cls commands on console pane on your powershell ISE which would also help to clear your output screen.
Screenshot of clear console pane button.
  • Undo/Redo: Undo/Redo is generally used when you want to correct the things in the script. You can use ctrl+z key combination for undo and ctrl+y key combination for redo.
Screenshot of Undo/Redo Icons.
  • Run Script (F5): This play icon runs the whole script at once, and if there is bug it would give at the end of the script execution.
  • Run Selection (F8): This icon runs the selected line from the script. Generally is helps to debug the bug in the script.
  • Stop Operation (ctrl+C or ctrl+break): This icon would stop the execution of the script in-between.

Screenshot of Run/Stop Icons.

  • New Remote Powershell TAB: You can connect to different computer or powershell of the computer remotely.
Screenshot of Remote Powershell Icons.
  • Start PowerShell.exe: This icon, pops out powershell output console where you can see your executed script/command.

Screenshot of Powershell.exe Icons, which is used to pop out console.

  • Script Pane Top: This will take script pane on top of powershell ISE.



  • Script Pane Right: This will take script pane on right of powershell ISE.

  • Script Pane Maximum: This will maximize the script pane in powershell ISE.



  • Show Command Window: This icon will pop out the command dialogue box out from powershell ISE console.


  • Show Command Add-On: This icon will show command box which would be attached with powershell ISE console. To view/unview command box in powershell you can click on this icon again. This pane consists of List of Modules and their respective command-lets. You can even search the cmdlt in the name search bar and can input the details by selecting the cmdlt which you want run. After inputting the details you can insert the cmdlt in the output console or in work space, where ever you require.

Screenshot shows Command Add-on on right pane of powershell ISE console.
You can run/copy/insert cmdlt using command add-on console. Just search for the cmdlt name, select the cmdlt, input respective options under the selected cmdlt and then accordingly you can select run/insert/copy option.

Screenshot shows how to use Command Add-on in output console.
So here we are end up with getting started with powershell basic concepts. In this blog we have learnt how to install powershell in a windows machine and learned some basics of powershell and its console. Feel free to comment below if you have any queries regarding this blog.

Comments

Popular posts from this blog

Command-Lets and Module

PowerShell and 'Get-Help' Basics