Introduction to PowerShell
PowerShell is a shell scripting language from Microsoft originally released for Windows in 2006. PowerShell was written to appeal to systems administrators and presents a great deal of its functionality as commands such as Get-ChildItem
, Get-Content
, New-Item
, and so on.
Microsoft Exchange was one of the first systems to embrace PowerShell with the release of Exchange 2007.
Active Directory tools followed a few years later along with tools to manage on-premises virtualization platforms from VMware and Microsoft Hyper-V.
More recently, PowerShell has been offered as a management tool for cloud platforms like Azure and AWS. In addition to modules that can be used to interact with either service, Azure and AWS both offer in-browser shells to directly manage services.
Windows PowerShell, or the Desktop edition, includes the original version through to 5.1, which is the final release of the Windows-specific shell. Windows PowerShell versions are based on .NET Framework.
In 2018, the first version of PowerShell Core was released with PowerShell 6. The move from .NET Framework to .NET Core allows the latest versions of PowerShell to run on Linux and macOS, as well as Windows.
Since then, PowerShell 7 has been released and continues to receive new features and updates. The core edition of PowerShell has seen a move through .NET Core 3.1 to .NET 8 with PowerShell 7.4.
The other significant difference between Windows PowerShell and PowerShell is that PowerShell 6 and above are open source. The project is on GitHub and is open to public contributors: https://github.com/powershell/powershell.
A significant number of community contributors have been driving change, making commands more usable and useful, adding new features, and fixing bugs. For example, Invoke-WebRequest
and Invoke-RestMethod
were completely overhauled in PowerShell 6, greatly improving how they perform while retaining much in the way of backward compatibility.
Several core commands were removed while these changes were being made. For example, the Get-WmiObject
and New-WebServiceProxy
commands have been removed. The reasons for this vary; in some cases, the commands are fundamentally incompatible with .NET Core. In a few cases, the commands were under restricted licensing agreements and could not be made open source. These differences are highlighted in this book and alternatives are demonstrated where possible.
Despite all this change, PowerShell still maintains strong backward compatibility, with very few breaking changes between the two editions. Operators and language keywords remain the same, and most changes are new features instead of changes to existing ones. Exceptions to this tend to be edge cases like parameter changes to Get-Content
when reading byte content. These differences in behavior are highlighted throughout this book. Lessons learned using Windows PowerShell can be applied to PowerShell 7, and they will continue to be applicable to future versions of PowerShell.
This book is split into several sections. Much of this book is intended to act as a reference. The following topics will be covered:
- Exploring PowerShell fundamentals
- Working with data
- Automating with PowerShell
- Extending PowerShell
While exploring the fundamentals of the language, this first section of the book attempts to cover as many of the building blocks as possible.
This chapter explores a diverse set of topics:
- What is PowerShell?
- The command line
- PowerShell editors
- Getting help
- Command naming and discovery
- About profile scripts
- Parameters, values, and parameter sets
- Introduction to providers
- Introduction to splatting
- Parser modes
- Experimental features