PowerShell is a scripting tool developed by Microsoft. Initially automation on Microsoft products (think Windows) was done by MS-DOS and CMD.exe, later it was often replaced by VBscript. But for more than a decade System Administrators mainly use PowerShell to automate the environment.
PowerShell is a great tool for automation, it can be used to automatically install a piece of software on ten, a hundred, or thousands of computers automatically. It can even be used to automate the entire data center.
PowerShell first came with a major Windows OS release with Windows 7. It was the new and improved scripting language, fixing the issues with previous languages. For example, cscript (used to run VBscript files) was very famous and easy to use, but was lacking a standardized language and was often exploited by viruses. And the older CMD.exe was completely outdated.
Since its release, PowerShell received a lot of updates and improvements, while development for CMD.exe and cscript.exe stopped ages ago.
And since the new flow at Microsoft (when Satya Nadella became the CEO), Powershell became a cross-platform language, now available on Linux and macOS as well.
(Interesting) Versions of PowerShell
- Windows Powershell 2.0: The first version that was automatically shipped with a Windows Operating System. This version came with Windows 7.
- Windows PowerShell 5.1: The default version that came with Windows 10 and even Windows 11 (even though version 7 of Powershell was released long before Windows 11 came to market)
- Powershell Core 6.0: Powershell is available cross-platform. This is released to general availability in January 2018 for Windows, macOS, and Linux.
- PowerShell 7: This version is the replacement of all previous versions. An interesting single command in Windows PowerShell to install this version:
Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
If you wish to know your PowerShell version, you can run $PSVersionTable. On my current system, the default PowerShell version is 5.1, but it is also running version 7 as you can see below screenshots.
PowerShell Commands and Aliases
Since PowerShell came to replace CMD.exe, it came with a concept of aliases. For backward compatibility and adaptability, Microsoft made it easy to use most of the common commands from CMD.exe (and even Linux/UNIX) in PowerShell. But instead of making the command twice, they made a pointer from those commands to the actual PowerShell command. For Example, the most commonly used “DIR” is an alias for “Get-ChildItem”, or CD is running “Set-Location”.
Powershell also supports all the “older” executables that are available in System32. So if you are used to running “Ping 8.8.8.8” to see if you are online (the DNS of Google), then that will still work since ping.exe is not a command or alias, but an application available to PowerShell.
When you run “Get-Command” you can get a very long list of commands that are available to you in PowerShell. These include cmdlets, aliases, functions, and applications,… so whenever you import modules, the list of “Get-Command” gets longer. It is pretty easy to create your own modules, so there are a lot of modules available out there. I suggest that you go and have a look at the PowerShell Gallery to get an overview of what you can find.
In the screenshot above you can also see that I imported the script “Packaging-App.ps1”, this is not a module (otherwise I would have to rename it to “.psm1”, but more about that later). And now my functions are also available as commands.
How to get help when in need
Of course, you can always Google something. But PowerShell comes with a very well-documented help function. Just use Get-Help and the name of the command you wish to understand better and you’ll be surprised. If it’s been a while, I suggest that you first run “Update-Help”. This will get the latest versions onto your machine.
And we all know that documentation is important, but PowerShell also comes with an option to ask for some examples. Examples are often more explanatory than the documentation itself. So below is a screenshot of examples for the “Add-Content”
Recent Comments