Introduction to Windows PowerShell?

nipun deelaka
5 min readOct 31, 2020

--

Photo by Tadas sar on flickr

The story starts in early 2000 when window users were exhausted by the command prompt terminal. Not only that urgency of the customer but also Microsoft itself want to add a more powerful shell with the windows operating system(OS). Instead of depending on the *NIX file systems’ shell architecture Microsoft able the build it Object-Oriented (‘oo’)way, build on top of the .NET framework and common language runtime(CLR) to harness the enrichment of the .NET ecosystem capabilities and give an experience of true pipeline and direct object manipulation. However, it’s still a shell among others. So, we have to understand, what is the shell and how it works.

So, What is a shell?

At the dawn of the information era, there was no graphical user interface(GUI), so from start to end, the computer shows only a black screen with white letters and blinking courser. when companies introduced the OS with GUI there was that command-line interface(CLI) part captured in a window, called shell( in windows)/terminal( in UNIX based OS).

Command-line interface(CLI) operates on the basic way of human interaction with the machine, such that input operation with arguments(parameters) and OS operates on that.

In our case, these operations must be pre-installed (by the OS provider or by our self). Up to window-NT OS .exe , .cmd , .bmt , .bat , etc. File types used to save command in the OS and .ps1 and .psd1 file types introduce to work with windows power-shell. most of the inbuilt commands like ($ ls, $ dir) save in the /system32 folder in your OS.

so, here, ipconfig.exe is the related folder the $ipconfig command in the CMD.

Also, you can write your own commands and save it as above mentioned type, and run it on the CMD. matter of fact, you have to write commands in a suitable fashion (batch script or dynamically typed scripting language.) and save it somewhere you like. And primarily you have to go to the saved directory before you run it.

firstcommand.bat file runs on the CMD [ $firstcommand ] as it says, ECHO “Hello, World ! “ it outputs in the CLI

before go further we have to clarify a thing,

Why is it two shells to windows? [ command prompt & PowerShell ]

As I mentioned before the 2006 release of the PowerShell there was a command prompt. it basically runs on the set MS-DOS commands written in *NIX architecture [ there was some new command in Windows-NT as well .] compatible with any legacy file system. OS they stay remain those type shell sake robustness.

Back to power shell,

What’s new in PowerShell?

as I said, pretty much everything in the power shell from the architecture is new. so you must argue with me, “then why is CMD commands still run on the power shell ?”. Okay, let’s dive deep into the power shell.

basically, every command in the power shell is structured into a ‘verb-noun’ pattern.

here, you can see the “Get-Location” command is the same command in Linux env. called “PWD” . that command constructed in a way the verb (Get) followed by -noun (-Location). [this PowerShell be weird because it is activated power line]

also, you will see, CLI calls ‘pwd’ command as the type of Alias. In PowerShell ‘commandlet’ or ‘cmdlet’ is the actual operating all the commands you enter. “Alias” gives a short form of that specific command and there are aliases according to the later CMD and Linux terminal

‘ls’, ‘dir’, ‘gcl’ aliases are referred to the cmdlet called ‘Get-Child’.

In the second command, I have entered in the above shell, it outputs all the attributes and properties to the ‘Get-ChildItem’ cmdlet. but, as you can see it’s a bit freaky command. that’s because as I said power shell has the ability to pipeline commands. that means resultant objects from the command ‘Get-Command’ feed into the ‘Select-Object’ command as a parameter.

In the above example, when I enter command ‘Get-ChildItem’ it returns a table list. actually each raw represents an individual object and table heads are their attributes. So, as I did next we can call attributes of all objects present or call particular attributes of a particular object.

here the command ‘select’ is an alias to ‘Select-Object’

we take the first object from the above object list by cmd piping. And we take the ‘name’ property out of it by using object-oriented dot operation.

This is just the tip of the ice-berg. you can learn a lot about how the .NET ecosystem works, batch scripts, power shell scripts, and so on under what we are discussed today.

Matter of fact, In the 2016 window introduce another new feature call Window subsystem for Linux (WSL).

Enables to run Linux genuine binary files on the windows without dual-booting or using a virtual environment. this makes a lot easier when you work with cloud computing (especially, software production in Docker environments.)

Summary

  • power shell is an ‘oo’ based advanced terminal to communicate with the computer hardware and application directly.
  • actually, it’s way more powerful than the old legacy based command prompt.
  • there are cmdlets, functions, aliases in the power shell. (built sake of simplicity)
  • we can pipe commands and use results of command as a normal object, therefore we can execute dot operations as well as methods.
  • finally, there is a new terminal called the WSL.

References :

--

--

nipun deelaka
nipun deelaka

No responses yet