Book Image

Learn PowerShell Core 6.0

By : David das Neves, Jan-Hendrik Peters
Book Image

Learn PowerShell Core 6.0

By: David das Neves, Jan-Hendrik Peters

Overview of this book

Beginning with an overview of the different versions of PowerShell, Learn PowerShell Core 6.0 introduces you to VSCode and then dives into helping you understand the basic techniques in PowerShell scripting. You will cover advanced coding techniques, learn how to write reusable code as well as store and load data with PowerShell. This book will help you understand PowerShell security and Just Enough Administration, enabling you to create your own PowerShell repository. The last set of chapters will guide you in setting up, configuring, and working with Release Pipelines in VSCode and VSTS, and help you understand PowerShell DSC. In addition to this, you will learn how to use PowerShell with Windows, Azure, Microsoft Online Services, SCCM, and SQL Server. The final chapter will provide you with some use cases and pro tips. By the end of this book, you will be able to create professional reusable code using security insight and knowledge of working with PowerShell Core 6.0 and its most important capabilities.
Table of Contents (26 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

Historical background


Let's start with some historical background. In the year 2002, Jeffrey Snover, the inventor of PowerShell itself, described the Monad Manifesto. Its first public beta release was on June 17, 2005. Monad was described as the next-generation platform for administrative automation, and it leveraged the .NET platform, providing excellent value propositions for application developers, application testers, power users, administrators, and Graphical User Interface (GUI) users:

  • Administrators should program faster and more easily—this was provided by having a unified parser and taking over many standard tasks
  • Monad should be object-oriented and always accept and return .NET Framework objects and not just text
  • It should be possible to execute scripts remotely on many computers
  • It should be possible to use GUIs

Afterwards, on April 25, 2006, Monad was renamed Windows PowerShell, and Release Candidate 1 of PowerShell version 1 was released at the same time.

On November 14, 2006, it was announced at TechEd Barcelona, Release Candidate 2 of PowerShell version 1 was finally released to the web for Windows XP SP2, Windows Server 2003 SP1, and Windows Vista.

Version 1.0 is obsolete today.

Starting with version 2, PowerShell was shipped with Microsoft operating systems. Therefore, it is integrated in Windows 7 and Windows Server 2008 R2, and was released for Windows XP with Service Pack 3, Windows Server 2003 with Service Pack 2, and Windows Vista with Service Pack 1.

PowerShell version 2 brought the first substantial change to the PowerShell API, and around 240 additional cmdlets. The creation of new cmdlets was simplified; they could also be written as scripts and combined to modules. PowerShell remoting was made available using WS-Management, and the updateable help, as well as job scheduling, has been introduced.

Starting with this version also, its reputation improved and its number of users increased. One reason for this is the release of the PowerShell Integrated Scripting Environment (ISE), a graphical interface with built-in console:

It is still commonly used today, and we will take a closer look at the available and recommended tools out there in the next chapter.

The next big step was achieved with PowerShell version 3, which is integrated with Windows 8 and Windows Server 2012. It is also available for Windows 7 SP1, Windows Server 2008 SP1, and Windows Server 2008 R2 SP1. It was shipped with Windows Management Framework 3.

Note

Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating systems.Open Data Protocol (OData) is an open protocol to allow the creation and consumption of queryable and interoperable RESTful APIs. The Common Information Model (CIM) is an extensible, object-oriented data model. The CIM can be used in combination with the WMI to create classes to manage an enterprise.

Big advantages of version 3 wereimproved code-writing techniques, such as IntelliSense, and automatic module detection. In addition, the number of cmdlets increased again, and PowerShell continued to gain more popularity. It also introduced major component upgrades and, very notably, the PSReadline integration feature, which enabled Jason Shirk's PSReadline module, which has been part of the core user experience since PS5. The AST was made available, allowing highly complex language parsing and paving the way for several major modules, including the PSScriptAnalyzer module.

The next version, PowerShell version 4.0, is integrated with Windows 8.1 and Windows Server 2012 R2, and has also been made available for Windows 7 SP1, Windows Server 2008 R2 SP1, and Windows Server 2012. Its biggest achievements are the Desired State Configuration, and some scripting enhancements, such as the new syntaxes for Where and ForEach.

Not long ago, PowerShell version 5 was released to the web on February 24, 2016, and is integrated with Windows Management Framework 5.0. The support of Chocolatey's repository-based package management was accomplished with new integrated cmdlets. To appeal to developers and administrators alike, classes such as .NET classes were added as well. Additionally, many improvements on DSC were introduced, such as the authoring of DSC resources using PowerShell classes. This version is a major milestone, with various new features and language extensions.

And lastly, PowerShell version 5.1 was released on August 2, 2016, and is integrated with the Windows 10 Anniversary Update and Windows Server 2016, and is also shipped within the Windows Management Framework 5.1. There is also a UserVoice open for this version, where feedback can be shared: https://windowsserver.uservoice.com/forums/301869-powershell.

Up until now, the versions are all primarily targeted to the Windows operating system, and therefore are called Windows PowerShell. But today, PowerShell is moving in a completely different direction, which started with making PowerShell open source (https://azure.microsoft.com/en-us/blog/powershell-is-open-sourced-and-is-available-on-linux/) on August 18, 2016. It was a substantial change, not only making the code open source, but also making PowerShell platform-independent and allowing the community to collaborate on and be involved in upcoming new features.

Shortly after, Windows Server 2016 was released, which brought us the Nano Server. The PowerShell version has also been divided in terms of the editions. Until then, every PowerShell release had been an edition of the Desktop, which can be retrieved (explained in Chapter 3Basic Coding Techniques) from the $PSVersionTable variable (available after PowerShell version 2):

Note

The PSEdition property contains either the value Desktop or Core, and can be retrieved from every PowerShell version. In addition, you can also see the currently used PowerShell version in the PSVersion property. The PSCompatibleVersions property includes all PowerShell versions that should be compatible, and the BuildVersion property can be useful to validate the current code source. Some fixes will only be delivered to the latest build versions of PowerShell.

Starting with Windows Server 2016 Nano Server, a new type of PSEdition was introduced, which is called Core and is bundled with .NET Core. This version can also be found in Windows IoT operating systems.

On November 17, 2017, the Release Candidate of PowerShell Core 6 was released, followed by the official General Availability (GA) on January 10, 2018. This was the start of a completely new direction, which is indicated by the added word, Core. Every PowerShell version 6.0 or higher will only be available with the PSEdition Core.

Due to some security issues, Windows PowerShell 2.0 was deprecated with the Windows 10 Fall Creators Update. We will cover the reasons and consequences in depth in Chapter 7, Understanding PowerShell Security.

Another big milestone was achieved on September 26, 2017, when PowerShell in Azure Cloud Shell (Preview) was made publicly available.

Currently, the development for PowerShell Core 6.1 and the official release for Azure Cloud Shell is ongoing, while very little work is now put into Windows PowerShell. Therefore, it is very unlikely that we will see new versions of Windows PowerShell, though the PowerShell Team has announced that security fixes will continue to be delivered. This brings us to the topic of the technical background and the roadmap and aims of PowerShell in the future.