Learn PowerShell Core 6.0 - David das Neves - E-Book

Learn PowerShell Core 6.0 E-Book

David das Neves

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 528

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Learn PowerShell Core 6.0

 

 

Automate and control administrative tasks using DevOps principles

 

 

 

 

 

 

 

 

 

 

 

David das Neves
Jan-Hendrik Peters

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Learn PowerShell Core 6.0

Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Commissioning Editor: Vijin BorichaAcquisition Editor: Rohit RajkumarContent Development Editor: Ronn KurienTechnical Editor: Prachi SawantCopy Editor: Safis EditingProject Coordinator: Kinjal BariProofreader: Safis EditingIndexer: Mariammal ChettiyarGraphics: Tom ScariaProduction Coordinator: Shraddha Falebhai

First published: July 2018

Production reference: 1250718

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78883-898-6

www.packtpub.com

 

To my wife, Jojo, for supporting me through my hard journey over the past few years and for making this book and my career possible.
—David das Neves
To my wife, Elsa, for supporting me throughout my career. To the brilliant minds that created PowerShell, for giving me endless joy and for enabling me to get a great job.
—Jan-Hendrik Peters
 
mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

PacktPub.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

Contributors

About the authors

David das Neves is a former software developer who has worked for Microsoft and works now as a Cloud Program Manager at Google. In his daily work he primarily helps enterprise customers to leverage the power of the Google Cloud Platform and to help them transform their businesses. Besides his work, he writes books and blog articles, organizes user groups, and speaks at conferences and other events all over the world.

He is very integrated in the PowerShell community, and he organizes the PowerShell user groups in Germany and Munich and speaks frequently at PowerShell conferences.

 

 

Jan-Hendrik Peters is an automation and DevOps professional by day and a developer for the AutomatedLab framework by night.

After working at an international retailer automating distributed POS support systems, he started working as a Premier Field Engineer for Microsoft Germany, where he helps customers automate their infrastructure on-premises and in the cloud.

When he is not working, he likes to spend his time brewing his own beer, curing his own bacon, and generally doing manual labor.

About the reviewer

Friedrich Weinmann helps companies with IT automation and code management tasks. He is an expert in PowerShell and knows his way around most Microsoft products.

He is actively engaged in the PowerShell community, running a user group, contributing to open source projects, maintaining several major projects himself, and speaking at other user groups and international conferences.

 

 

 

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Learn PowerShell Core 6.0

Dedication

Packt Upsell

Why subscribe?

PacktPub.com

Contributors

About the authors

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Current PowerShell Versions

Technical requirements

Historical background

Overview of different versions of Powershell

PowerShell Editions 

Windows PowerShell 5.1

PowerShell Core 6

PowerShell Open Source

Downloading the source code

Developing and contributing

The goals of PowerShell Core 6

Dependencies and support

Compatibility

Cross-platform remoting

Azure Cloud Shell

Features of PowerShell in Cloud Shell

Future of PowerShell

Summary

Questions

Further reading

PowerShell ISE Versus VSCode

Introduction to currently available tools

Recap

PowerShell ISE

Visual Studio Code

Introduction

Download

Installation

First start

Basics

ISE versus VSCode

Summary

Questions

Further reading

Basic Coding Techniques

Comments

Regions

Types

Variables

Commands and parameters

Approved verb list

PSDrives and PSProviders

PowerShell's scripting language

Script blocks

Operators

Pipeline operator

Type operators

Arithmetic operators

Assignment operators

Comparison operators 

Logical operators

Split and join operators

Bitwise logical operators

Replace operator

Unary operators

Language constructs

Indentation

If...ElseIf, and Else

Switch

Loops

for loop

do loop

while loop

foreach loop

break and continue loops

Error handling

Non-terminating

Terminating errors

Remoting

Types of remoting

Summary

Questions

Further reading

Advanced Coding Techniques

Technical requirements

Working with credentials

Working with external utilities

Pipeline and performance

Performance

Parallel execution

Working with APIs

Creating a REST endpoint

Create

Read

Update

Delete

Interacting with a RESTful API

Working with events

Object events

WMI events

Engine events

Remote events

Custom formatting

Custom type extensions

Summary

Questions

Further reading

Writing Reusable Code

Best practice guidelines

Code layout

Brace placement

Naming conventions

Aliases and parameter names

Readability

Function design

Output

Cmdlet output

Conveying messages

Compatibility

Comments

Header or disclaimer

Functions

Script blocks

Function declaration

The parameter attribute

Parameter sets

Pipeline input

Cmdlet binding attribute

Scopes

Dot-sourcing code

Help files

Help-driven development

Code signing

Possible solutions

Digital certificates

Public key Infrastructure

Self-signed certificates for testing

Preventing changes and execution

Proving that changes were made

Modules

Module architecture

Combining multiple functions

The module manifest

Managing complexity

Deployment and upgrade

Version control

Changelog

Recovery

Revert

Checkout

Reset

Branching

Merging

Possible solutions

TFS

Git

SVN

PSScriptAnalyzer

Summary

Questions

Further reading

Working with Data

Registry

Files

CSV

XML

CLIXML

JSON

Classes 

Summary

Questions

Further reading

Understanding PowerShell Security

Current situation around PowerShell

Is PowerShell a vulnerability?

Principle of Least Privilege

The community

Version 5

Evergreen

Secure coding

Remoting

Double hop 

ExecutionPolicy

Bypassing the ExecutionPolicy

Executing PowerShell without PowerShell.exe

Constrained language mode

 AppLocker

How the Constrained Language Mode is enforced

Windows Defender Application Control

Obfuscation

Logging

AMSI

Prioritizing technical security controls

Summary

Questions

Further reading

Just Enough Administration

Technical overview

Session authoring

Role capabilities

Merging role capabilities

Cmdlet visible in one role

Cmdlet visible in multiple roles

Validation is used in one role

Validation is used in multiple roles

ValidateSet and ValidatePattern are mixed

Session configurations

Language mode and session type

Transcripts

Accounts

Connecting users

Virtual account

Group-managed service account

User drive

Deploying session configurations

Individual activation

Distributed activation

Desired State Configuration

Use cases

Summary

Questions

Further reading

DevOps with PowerShell

What is DevOps?

WinOps

DevSecOps

Why DevOps

Traceability

Reliability

Speed

Test-driven development

Continuous integration

Continuous deployment

Challenges of DevOps

The value of PowerShell

Summary

Questions

Further reading

Creating Your Own PowerShell Repository

Package management

Centralization

Interacting with repositories

Knowledge management

Documentation with PlatyPS

PowerShell repository

Setup

Modules

Signing

Version control

PowerShellGet

Execution

Dedicated user

JEA

Deploying and upgrading

PowerShellGet

End user updates

Automatic updates

JEA servers

Summary

Questions

Further reading

VSCode and PowerShell Release Pipelines

Configuration

Interface

Extensibility

Preparing for a release pipeline

Working with different hosts

Plaster

Creating templates

Packaging templates

PSScriptAnalyzer

Pester

Mock

Mock .NET calls

Describe

Context

It

Running tests

Git

Centralized workflow

Forking workflow

CI tools

Bringing it all together

Summary

Questions

Further reading

PowerShell Desired State Configuration

Introducing DSC

Why Desired State Configuration?

Configurations

Local Configuration Manager – LCM

Push

When to use

Pull

When to use

Security

Resources

Built-in resources

Community

Custom

Composite

DSC Core

Summary

Questions

Further reading

Working with Windows

Retrieving the latest PowerShell version

WMI CIM

Delivery Optimization

Retrieving all log events and files for update issues

Turning off energy-saving mechanisms

Verifying installed updates

Working with apps

EventLog

ETL parsing

Convert-PPTX to PDF

Summary

Questions

Further reading

Working with Azure

Azure 101

Resource groups

Tags

Resources

PowerShell in Azure Cloud Shell

The Azure drive

Resource group deployment

Finding templates

Resources

Parameters and variables

Functions in templates

Individual deployments

Summary

Questions

Further reading

Connecting to Microsoft Online Services

Office 365

Exchange Online

Using some cmdlets

SharePoint Online

Microsoft Teams

Summary

Questions

Further reading

Working with SCCM and SQL Server

System Center Configuration Manager

Logging

PowerShell App Deployment Toolkit

SQL Server

Working with the SqlServer module

The SQL Provider

Connecting to SQL instances

Running manual queries

Working with availability groups

Masterkeys, encryption, and credentials

Working with the dbatools module

Discovering SQL instances

Connecting to SQL instances – the SqlInstance parameter

Running manual queries

PowerShell to SQL

Navigating the module

Backup, restore, and test

Deploying maintenance insight tools

Migrations made easy

Working with the Reporting Services module

Connecting to the Reporting Services server

Administrating the service

Managing the data in the service

Working with content

Navigating the structure

Exporting content

Importing content

Configuring SSRS servers

Working with the dbachecks module

Configuration

Feel the power

Summary

Questions

PowerShell Deep Dives

Creating XAML GUIs with PSGUI

Scalable DSC configuration

The problem

The setup

Configuration data

Configurations

Build

ConvertFrom-String

LINQ

OpenFileDialog

Username to Security Identifier (SID)

SHiPS

PSDefaultParameterValues and PSBoundParameters

PSDefaultParameterValues

PSBoundParameters

ConvertTo-Breakpoint

Summary

Questions

Further reading

PowerShell ISE Hotkeys

Keyboard shortcuts for editing text

Keyboard shortcuts for running scripts

Keyboard shortcuts for customizing the view

Keyboard shortcuts for debugging scripts

Keyboard shortcuts for Windows PowerShell tabs

Keyboard shortcuts for starting and exiting

References

VSCode Hotkeys

Default keyboard shortcuts

Basic editing

Rich languages editing

Navigation

Editor/Window management

File management

Display

Search

Preferences

Debug

Tasks

Extensions

References

Assessments

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

Chapter 12

Chapter 13

Chapter 14

Chapter 15

Chapter 16

Chapter 17

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

The book you are currently reading is the collaborative effort of David and Jan-Hendrik and represents the accumulated knowledge of the authors use of PowerShell in corporate environments, ranging from medium-sized businesses to large international organizations. We will examine the past, present, and future of PowerShell and guide you through your journey of becoming a DevOps and security-minded PowerShell professional through dedicated chapters on security, DevOps, advanced scripting techniques, and accessing cloud resources.

Who this book is for

This book is intended for IT professionals and developers who have already taken their first steps with PowerShell and now want to unlock their full potential. IT professionals and developers looking to automate simple to complex tasks will find this book useful as well. But even seasoned PowerShell users will find worthwhile information, as we deep-dive into many different topics throughout the book, such as performance and security.

What this book covers

Chapter 1, Current PowerShell Versions, introduces Windows PowerShell and PowerShell Core and gives you a general overview of the past, present, and future of PowerShell.

Chapter 2, PowerShell ISE Versus VSCode, compares the different editors that are capable of editing and executing PowerShell code. We compare PowerShell ISE and VSCode comprehensively; VSCode is the de facto successor to PowerShell ISE.

Chapter 3, Basic Coding Techniques, goes over the basics of PowerShell scripting, such as cmdlets, using the pipeline, and PowerShell's type system. We will look into different language keywords and operators to get you going.

Chapter 4, Advanced Coding Techniques, extends your knowledge by examining the performance of pipeline operations, enabling you to interact with web services and giving you full control of the formatting and type system that is built into PowerShell.

Chapter 5, Writing Reusable Code, introduces you to a set of best practices when developing code and demonstrates the use of functions and modules. We will start looking at version control systems and digitally signed code as well.

Chapter 6, Working with Data, shows you how to work with different kinds of data in PowerShell, from accessing the registry to developing a class and using JSON in your scripts.

Chapter 7, Understanding PowerShell Security, is an in-depth primer on security in PowerShell and the multitude of options that attackers and defenders have to make use of.

Chapter 8, Just Enough Administration, dives into a new feature of Windows PowerShell called Just Enough Administration, in order to apply role-based access control (RBAC) to products that do not have their own RBAC solution in place.

Chapter 9, DevOps with PowerShell, is short introduction to DevOps that focuses on what PowerShell can do to support DevOps scenarios with integrated unit testing and flexibility in a release pipeline.

Chapter 10, Creating Your Own PowerShell Repository, focuses on the package management capabilities of PowerShell by building a NuGet gallery from scratch and showing you how to work with external and internal package sources.

Chapter 11, VSCode and PowerShell Release Pipelines, concentrates on using PowerShell in a CI/CD context with a release pipeline for your code. We show you additional concepts around the pipeline, such as unit testing and source code management, as well as some helpful PowerShell modules.

Chapter 12, PowerShell Desired State Configuration, introduces you to a feature of Windows PowerShell that helps you greatly in following DevOps principles by giving you a way of defining infrastructure as code. We will examine the key components of DSC to prepare you for the deep dive in Chapter 17, PowerShell Deep Dives.

Chapter 13, Working with Windows, concentrates on the components of PowerShell that Windows administrators can leverage to maintain, troubleshoot, and tune their Windows operating system.

Chapter 14, Working with Azure, shows you the capabilities of PowerShell in a cloud context. We will look at how you can use PowerShell with Azure in DevOps and traditional IT scenarios alike.

Chapter 15, Connecting to Microsoft Online Services, goes one step further than the previous chapter and shows you how to connect to other hosted services, such as MSOL, as well, introducing you to Office 365, SharePoint Online, Exchange Online, and Microsoft Teams.

Chapter 16, Working with SCCM and SQL Server, introduces you to the ways of working with System Center Configuration Manager and SQL Server with PowerShell. We will not only dive into the built-in modules, but will also showcase great community-driven modules.

Chapter 17, PowerShell Deep Dives, concentrates on several scenarios that are either seldom used or that are not well documented, such as using DSC in a corporate environment, developing user interfaces in PowerShell, and improved debugging experiences.

To get the most out of this book

To get the most out of this book we assume the following prerequisites:

Basic understanding of structural and procedural programming

Basic understanding of object-oriented programming

A machine capable of running PowerShell Core

For some examples that are inherently related to Windows, a machine capable of running Windows PowerShell, for example, Windows Server 2016 or Windows 10

To follow along with advanced exercises that require access to one or more servers, we also recommend you install and use the AutomatedLab framework. Instructions can be found at https://github.com/automatedlab/automatedlab and in the software and hardware list in this book. AutomatedLab allows you to easily deploy lab infrastructures with several automatically configured services, such as Active Directory Domain Services, Certificate Services, SQL, and much more.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packtpub.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learn-PowerShell-Core-6.0. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/LearnPowerShellCore6_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "In the next screenshot, we are coding in the test.ps1 file."

A block of code is set as follows:

function UsesPipeline{ param ( [Parameter(ValueFromPipeline)] [string] $PipedObject )

Any command-line input or output is written as follows:

git clone --recursive https://github.com/PowerShell/PowerShell.git

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Now, install the extension by pressing Install, which you can find on the top right-hand side."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

Current PowerShell Versions

Before we start with the first chapter, we will very briefly discuss the content of this book and its aims. As you know, there are many PowerShell books out there, which also deliver very rich content. But it has been our experience that some topics are missing in most of them. In addition, we recognized new topics, especially coming with the new PowerShell Core v6, but also by addressing more and more security topics and targeting enterprise environments.

Therefore, we want to introduce PowerShell in terms of all of the topics targeting enterprise companies, such as PowerShell Security, Centralization, Release Pipelines, Just Enough Administration (JEA), and more, but also in terms of completely new topics arising from PowerShell Core 6 and the new editing tool, Visual Studio Code. The intention, overall, is to deliver a solid PowerShell book that is a useful resource for beginners, but is also packed full of completely new and reworked content, which even PowerShell professionals might benefit from.

Today, we have a broad number of PowerShell versions available, starting with PowerShell 1 up to the Windows PowerShell 5.1, PowerShell Core 6, and even the PowerShell in Azure Cloud Shell. Most enterprise companies primarily work with PowerShell versions starting from 2 up to 5.1. But, what PowerShell version should you use, and how can each of them be installed and made available? This is what the first chapter is about; its aim is to give you some background information and a good overview of all currently available PowerShell versions, how to install them, and how to use them.

These are the topics we'll be covering in this chapter:

Historical background

Overview of different versions of PowerShell

Windows PowerShell 5.1

Upgrading to the latest PowerShell version in Windows environments

PowerShell Core v6

Differences between Windows PowerShell and PowerShell Core v6

PowerShell open source

Goals of PowerShell Core v6

PowerShell in Azure Cloud Shell

Future of Windows PowerShell

How to contribute to the open source project

Technical requirements

Most of the examples shown in this book are executed with Windows PowerShell 5.1. You can work with this latest Windows PowerShell version either by just using a Windows 10 machine, or by upgrading the PowerShell version of your current Windows environment. This is described later in this chapter, in the Windows PowerShell 5.1 section.

The following operating systems will be supported: Windows 7 Service Pack 1, Windows 8.1, Windows 10, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, and Windows Server 2016.

The code for the book can be found at https://github.com/PacktPublishing/Learn-PowerShell-Core-6.0. It includes a folder for each chapter and additional installation instructions.

Some examples use PowerShell Core 6. You can download and install the latest PowerShell Core version at https://github.com/PowerShell/PowerShell/releases.

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.

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 were improved 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 3, Basic Coding Techniques) from the $PSVersionTable variable (available after PowerShell version 2):

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.

Overview of different versions of Powershell

To provide the best overview, we will focus on the most valuable information. First, you need to know about the two different versions and the differences between them.

PowerShell Editions 

There are two editions of PowerShell:

Desktop Edition

This version uses the

full .NET CLR

. It is primarily used in Windows Desktop and Core Server environments.

Core Edition

:

This version uses

.NET Core

. It is primarily used in Windows IoT and Nano Server environments.

The $PSVersionTable variable holds the information for the currently used PSVersion and PSEdition.

The same terminology can be observed with Windows PowerShell versus PowerShell Core:

Windows PowerShell

is built on top of the .NET Framework:

Versions 1 to 5.1

Available on Windows and Windows Server only

Delivered as a built-in component and via WMF

Built on top of the .NET Framework (also known as FullCLR)

$PSVersionTable.PSEdition

is set to Desktop

PowerShell Core

is built on top of .NET Core:

Version 6++ (and Nano Server/Windows 10 IoT)

Available on Windows, macOS, and Linux

Delivered via MSI, ZIP, or PKG (macOS)

Built on top of the current .NET Core version (also known as CoreCLR)

$PSVersionTable.PSEdition

is set to Core

PowerShell Core is available in Windows Server 2016 Nano Server and Windows 10 IoT, but also in PowerShell Core 6 and newer versions.

This information brings us to the following overview:

Windows PowerShell 5.1

Windows PowerShell 5.1 is the latest, and probably last, version of Windows PowerShell, and is therefore of special interest in Windows environments. All operating systems with Windows 10 or Windows Server 2016 and higher come with the latest PowerShell version integrated. But, as you know, in many enterprise environments, you will always find machines with legacy operating systems, which may come with completely different versions.

One of the most important recommendations is to always use the most recent versions. PowerShell is backward-compatible, and therefore you should install Windows PowerShell 5.1 on all your machines, barring those known to be incompatible. This can be achieved with the previously described Windows Management Framework.

Because Windows PowerShell is built on top of the .NET Framework, you will need to have .NET version 4.5.2 installed on all computers before applying WMF 5.1 to them. There have been some issues with previous Windows Management Framework versions, which needed the consecutive installation of all of them, but these have been fixed in the latest version (5.1). So, having .NET Framework 4.5.2 installed on the computers is the only dependency you must fulfill.

Supported Operating Systems:

Windows Server 2012 R2

Windows Server 2012

Windows Server 2008 R2 SP1

Windows 8.1

Windows 7 SP1

Windows Management Framework 5.1 includes updates to Windows PowerShell, WindowsPowerShell Desired State Configuration (DSC), Windows Remote Management (WinRM), and Windows Management Instrumentation (WMI).

PowerShell version 5.1 should be backward-compatible in most cases, but there are some known issues—for example, with Exchange Server 2010. A recommendation is to deploy the WMF 5.1 in waves and revalidate any existing scripts for possible issues after the upgrade.

There are different WMF 5.1 packages available for different operating systems:

If you have a distribution system in place, such as System Center Configuration Manager, you can easily deploy WMF 5.1 to all your machines. Alternatively, you can also accomplish this task through PowerShell remoting and command-line execution.

PowerShell Core 6

Before PowerShell and PowerShell Core 6 were made open source, we had the big PowerShell monolith in place, which was developed and maintained by the PowerShell Team. But there had been a lot of problems with this situation:

Lack of agility/velocity

: There was a legacy control in place, and it was a painful and manual release process with nightly builds tied to Windows having long-running test suites.

Lack of visibility

: The code reviews were done via email, and the issues and working items were stored in many different places.

Difficult manual feedback process

: The Connect/UserVoice items had to be manually triaged into internal work items, and the engineers were completely disconnected from feedback loops.

Therefore, the idea was to set up better engineering processes with rapid, independent builds and fast, transparent tests with automated packing for every platform. In addition, the collaboration needed to be improved in terms of the visibility of the work for all interested parties (first and third parties). A clear project management and release process was needed to provide visibility into current and future releases, as well as a governance system for approving changes and additions to PowerShell.

This all led to PowerShell being made open source, which additionally brought the following benefits with it:

Enabled the community to directly help in finding and fixing bugs

Enabled more direct and powerful feedback from the community

Improved visibility into team priorities

Increased credibility from the Linux community

PowerShell Open Source

PowerShell was completely restructured and published on GitHub; it can be found at https://github.com/PowerShell/PowerShell:

And new documentation was added at https://docs.microsoft.com/en-us/powershell/:

Downloading the source code

You can just clone the repository with the following Git command:

git clone --recursive https://github.com/PowerShell/PowerShell.git

Developing and contributing

There is also a contribution guideline available, which can be found at https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md. It contains some information about working with Git and how to create pull requests.

To be even more connected with the community, the PowerShell Team has set up regular open PowerShell Core Community Calls. In these calls, RFCs, feature requests, and contentious bugs are discussed. The team will also provide a quick update about the status of the project and the direction it is headed in. At the following link, you will also find the previously recorded community calls and an ICS file for your calendar application: https://github.com/PowerShell/PowerShell-RFC/tree/master/CommunityCall.

The goals of PowerShell Core 6

There have been three primary goals for PowerShell Core 6:

When we examine each of these goals, it becomes clear how PowerShell Core came into being and why it is a great management tool for any infrastructure:

Ubiquity

describes the platform-independency to work with PowerShell on Windows, Linux, and macOS operating systems. This is necessary because heterogenous environments are today's norm, and they are important to developers and IT professionals.

Cloud

refers to the intention of being built for cloud scenarios, because IT is moving towards Azure, REST APIs (Swagger/OpenAPI), and other public clouds. For this, major improvements have been made to the 

Invoke-WebRequest

Invoke-RestMethod

, and

ConvertFrom-Json

 

cmdlets. 

There is a collaboration with the Azure PowerShell team to support PowerShell Core. Third-party vendors, such as VMware and AWS, are also working to support PowerShell Core.

Community

refers to being open source, contributing directly to the product, and allowing the retrieval of customer feedback directly to the engineering team. The current

Request for Comments

(

RFCs

)—asking for feedback for the current roadmap/new features or breaking changes

, milestones, projects, and issues

should always be transparent and publicly available. This means that we have pull requests against code, tests, and documentation. In addition, issues from the community are dynamically reprioritized, which can also be discussed in the PowerShell Core Community Call. These calls are free to join for everybody, and you can just raise your voice and discuss your feedback directly with the engineers.

Dependencies and support

As you know, PowerShell Core 6 and all following PowerShell versions depend on .NET Core. The first version of .NET Core was released in 2016:

On August 14, 2017, .NET Core 2 was released, on which PowerShell Core 6.0 is based. It implements .NET Standard 2.0 with the following conditions (https://github.com/dotnet/standard):

.NET Standard defines a set of APIs that have to be implemented by all .NET platforms, as shown in the following diagram

.NET Standard 2.0 is implemented by .NET Core

.NET Standard 2.0 includes a compatibility shim for .NET Framework binaries

.NET Standard will replace Portable Class Libraries (PCLs)

You can see the .NET Standard API definition in the .NET/standard repository on GitHub.

In the following diagram, you can see this implementation for all .NET platforms:

Though there were no substantial changes made to the language itself in the .NET Standard 2.0 Release, the increase in API size—and hence, the tools available—more than justified the increased footprint:

Version

Number of APIs

Growth %

1.0

7,949

1.1

10,239

+29%

1.6

13,501

+32%

2.0

32,638

+142%

.NET Standard 2.0 includes the most important APIs and brings almost all .NET Framework 4.6.1 APIs to .NET Core 2.0:

PowerShell Core will be supported by Microsoft's Modern Lifecycle Policy.

The Modern Lifecycle Policy covers products and services that are serviced and supported continuously. Under this policy, the product or service remains in support if the following criteria are met:

Customers must stay current as per the servicing and system requirements published for the product or service

Customers must be licensed to use the product or service

Microsoft must currently offer support for the product or service

Compatibility

Because of the changed underlying .NET Framework, compatibility may also have changed. One big benefit here is that .NET Standard 2.0 is implemented with .NET Core, which provides a binary compatibility with existing .NET assemblies. Because many PowerShell cmdlets and modules depend on them, these continue to work with .NET Core.

Many modules shipped as part of Windows haven't been explicitly ported to .NET Core, but may also continue working with the underlying .NET Standard and the implementations of CDXML. The CDXML files define the mappings between PowerShell cmdlets, and CIM class operations, or methods. Everything that is implemented with a CDXML should keep working.

But there are also some known exceptions:

Workflows

Snap-ins

DSC resources (for now, moves to DSC Core)

WMI v1 cmdlets (

Get-WmiObject

,

Invoke-WmiMethod

, and so on)

A handful of other missing cmdlets

After the first public release of PowerShell Core, we are currently seeing the community and the product groups port their modules and cmdlets to PowerShell Core. It will take some time before most of the existing cmdlets continue to work on PowerShell Core.

Due to some naming collisions in Linux environments, the executable of PowerShell Core has been renamed from PowerShell.exe to pwsh.exe.

Cross-platform remoting

With the focus of being platform-independent, some changes to the remoting techniques had to be made. As you can see in the following diagram, PowerShell Core supports PowerShell Remoting (PSRP) over WSMan with Basic authentication on macOS and Linux, and with NTLM-based authentication on Linux. Kerberos-based authentication is not yet supported.

PowerShell Core also supports PSRP over SSH on all platforms (Windows, macOS, and Linux). Since this feature is still actively being developed, it is not recommended to use it in production. We will look at how to establish remote connections in Chapter 3, Basic Coding Techniques, and Chapter 4, Advanced Coding Techniques:

OpenSSH can be installed on Windows 10 1709 and later via the optional features:

Azure Cloud Shell

Azure Cloud Shell can be found in the Azure Portal, as shown in the following screenshot:

Afterwards, the Shell will open either in Bash or PowerShell. The connection will look like this and opens in the Azure drive (Azure:):

The PowerShell version that is used for PowerShell in Azure Cloud Shell currently is version 5.1 in the Desktop Edition, which is hosted in a Docker container. We will elaborate on that in Chapter 14, Working with Azure which is dedicated to PowerShell and Azure:

Features of PowerShell in Cloud Shell

The PowerShell experience builds upon the benefits of Azure Cloud Shell, such as the following:

Secure automatic authentication from virtually anywhere

Choice of shell experience that best suits the way you work

Common tools and programming languages included that are updated and maintained by Microsoft

Azure File Storage, which allows access to an Azure file share in a storage account for a small monthly fee associated with data storage. File Storage is mapped as the cloud drive and can be used to exchange data.

The PowerShell experience adds the following:

The new PSDrive for Azure (

Azure:

)

this provides easier searching capabilities within Azure resources

Dedicated and built-in commands

Data persistence via cloud drive

Custom modules

User profile

Rich tools support

Azure PowerShell

Nano and VIM (with PS IntelliSense)

Git and sqlcmd

For more information on PowerShell features, refer to https://aka.ms/cloudshell/PowerShell-Docs.

The first big achievement here is the new Azure drive. Here, you can just work directly on Azure and retrieve your Azure resources, as shown in this screenshot:

Feedback on Azure Cloud Shell is tracked on UserVoice via issues and feature requests: https://feedback.azure.com/forums/598699-azure-cloud-shell.

Future of PowerShell

The future of PowerShell lies in PowerShell Core 6 and newer, with the focus to work platform-independently and together with the community on the new versions. We will see a transitioning phase in the upcoming years, where most of the existing modules are ported from Windows PowerShell to PowerShell Core.

In addition, we will see a lot of work being done within Azure Cloud Shell, providing more automation to work with Azure resources from anywhere. Windows PowerShell, though, will not gain additional features, but will keep being a built-in, supported component of Windows 10 and Windows Server 2016.

Summary

In this chapter, you learned about the different PowerShell versions, what the differences are, and how PowerShell is evolving. With this knowledge, you know which PowerShell versions you should use for different scenarios, such as Windows PowerShell 5.1, PowerShell Core 6 and newer, or PowerShell in Azure Cloud Shell.

In the next chapter, we will look at the tools that the different PowerShell versions can be used with and compare the features of both Visual Studio Code, as well as the Integrated Scripting Environment.

Questions

What is the latest PowerShell version in Windows environments?

How can you retrieve the version number and the PSEdition?

What is the difference between the Core edition and Desktop edition?

How can you deploy the newest Windows PowerShell version to your systems?

How can you install OpenSSH on a Windows Desktop?

What is the main difference between Windows PowerShell 5.1 and PowerShell Core 6?

What are the main goals of PowerShell Core 6?

How can you use PowerShell in Azure Cloud Shell?

Further reading

Please see the following for further reading relating to this chapter:

Install and Configure WMF 5.1

:

https://docs.microsoft.com/en-us/powershell/wmf/5.1/install-configure

Azure Cloud Shell

:

https://azure.microsoft.com/en-us/features/cloud-shell/

PowerShell ISE Versus VSCode

In the last chapter, you learned about different PowerShell versions and how to use them. But one of the most important things for creating fast, reusable, high quality code work with good tools. As you know from the previous chapter, one of the most popular tools is the integrated PowerShell ISE in Windows. It provides an easy UI and also some debugging possibilities. Unfortunately, it has not received many updates since it was initially released. This is why other tools were raised in the meantime. One of the most important ones is Visual Studio Code. This chapter will show the differences between the two tools and introduce VSCode. In Chapter 11, VSCode and PowerShell Release Pipelines, this is going to be continued and some advanced techniques with VSCode will be described.

These are the topics we'll be covering in this chapter:

Introduction to currently available tools

The PowerShell ISE

VSCode:

Introduction

Download

Installation

First Start

Basics

The ISE versus VSCode

Introduction to currently available tools

There are many tools available to write PowerShell code or even to create PowerShell-based GUIs. Many administrators just stick to the PowerShell Integrated Scripting Environment (ISE), but there are also a lot of other different tools available. Therefore, I want to give an overview with a small description of each tool and also make a recommendation. 

The following list is not an exhaustive list of tools but includes tools the authors have personal experience with. When choosing the proper tool for scripting, we can only recommend testing the tool in your day-to-day work properly before. Free and open source tools might, for example, be superior to paid tools or might be a better fit for your scripting style:

PowerShell Console

Free

The PowerShell Console is the most basic tool for executing PowerShell commands. Just open PowerShell.exe from Command Prompt to start using it. It provides IntelliSense (shows command suggestions when writing) and integrated help. 

It is lacking any UI options and is therefore just an option to open and use PowerShell in an interactive way.

ISE PowerShell

Free

PowerShell ISE comes with all Windows versions that are being used today.

It provides a good rudimentary feature set, which helps for most scenarios.

ISE PowerShell + ISESteroids

With costs

ISESteroids is an add-on from Tobias Weltner, which brings many additional features to the ISE, especially for professional and faster coding. 

This combination has been my preferred tool for years, but was recently replaced by Visual Studio Code.

Visual Studio 2017 Community/Professional

Free/with costs

Visual Studio is the complete development environment, which every developer loves. It might be overwhelming in terms of features and functions, and is therefore very rarely used.

You need to install the PowerShell extension to get language assistance within Visual Studio.

Visual Studio Code

Free

This is probably the best tool for PowerShell scripting. You can create PowerShell scripts with it after having the PowerShell extension installed. We will get into this tool in depth.

I use this tool on a daily basis and would never replace it.

SAPIEN PowerShell Studio

With costs

PowerShell Studio is very often used by administrators to create professional GUIs. Though I personally never used it for a long period of time, it is very well known as one of the best tools to create PowerShell-based GUIs. Its latest version also provides support for PowerShell Core 6.

SAPIEN Primal Script 2017

With costs

Primal Script is a professional editor that supports over 50 languages and file types. From my experience it is quite a useful editor, but not as frequently used as the other ones. 

PoshGUI

Free

PoshGUI is a great web-based tool to create code for PowerShell-based GUIs that are working on Windows Forms. It can be found at https://poshgui.com/.

You should use it if you want to very quickly create these types of GUIs or want to learn how they are created, as you can take the created code as a learning resource.

PowerGUI

Free

PowerGUI was a very good tool, which also provided additional features for working with WMI or converting VBS into PowerShell. Unfortunately, it is not continued anymore and therefore you should not spend too much time with it.

Admin Script Editor                                       

                                       

Free

This is very rarely used editor.

As you can see, there is a vast list of possible tools available. Most administrators and IT-professionals have been using and probably still are using the ISE. In addition, we are seeing huge investments made into VSCode and an increasing adoption rate of this new tool, as well. Therefore, we will focus on these specific two tools, as both are also available cost-free.

Recap

In our book we continue on with only the PowerShell ISE and VSCode. We chose the ISE because it is a built-in tool that is always available with the Windows Management Framework. It is easy to use and readily available. Especially for beginners, the interface is very clean and not as overwhelming as the ISE + ISE Steroids or VSCode for that matter.

As the successor to the ISE, we will concentrate on VSCode for the remainder of the book. Since no additional development effort is flowing into the ISE and VSCode is the successor, we will not concentrate on additional tools. VSCode is available on more operating systems than the ISE, is completely free, and already has a huge amount of extensions that can be used.

PowerShell ISE

The PowerShell ISE was introduced with PowerShell v3. Unfortunately, it has not evolved too much from past versions, which is why it is losing its importance and is now finally going to be replaced by Visual Studio Code. Though replacing might be the wrong verb in this context—the PowerShell ISE will continue to stick to the Windows PowerShell version on Windows systems. VSCode, in comparison, is free and easily downloadable on every device. The problem is that the PowerShell ISE is still being used by the largest number of people—even today. This is why I am still explaining it very briefly, but then will move on to VSCode and prioritize VSCode in the whole book. You will recognize by yourself that VSCode is the more powerful and flexible tool; it is also continuously getting new features.  

PowerShell ISE can be executed through PowerShell_ISE.exe, which is located in the C:\Windows\System32\WindowsPowerShell\v1.0\ folder. The user interface is very simple and looks like this:

As you can see in the preceding screenshot, you have the dark blue console pane and the white script pane. In the script pane, you can prepare scripts before executing them either in parts or as a full script. For this you also have hotkeys available, which you should get to know and use them in a frequent manner:

F5

for the execution of the whole script

F8

to only run the selection

A complete overview of all hotkeys can be found in Appendix A, PowerShell ISE Hotkeys.  You should get to know most of these; this will help you to create faster scripts and work more efficiently with the tools.

In addition, you can also use the ISE for debugging. With the F9 hotkey, you can set breakpoints in the script pane. A breakpoint forces the debugger to stop at the specified line, where you can then take a dedicated look at the variables and step through the whole script line by line. To accomplish this, you have three actions available after hitting a break point:

For most coding languages and tools, these three options are available:

F10

just executes the whole line and continues to the next line. If there is a function used in this line, this function is just

stepped over

, which is why this is named 

Step Over

.

F11

executes every line of code in its minimal pieces. This means that by the functions that are used are being opened and each single line of code is being stepped through. This is why it is called

Step Into

.

The last one is

Shift

+

F11

, which jumps out of the current function block. The next line shown is the initial executing line of the function. This hotkey can be used in combination with

F11

 to jump into and then 

Shift

+

F11

 to jump back out of functions. This is why it is called

Step Out

.

This is the basic knowledge about debugging that we will use throughout the whole book. It is important that you get used to the possibilities in debugging and use them frequently. Coming with PowerShell, there are many skills you need to evolve. People with a developer background will already have many helpful skills. But if you are not familiar with these techniques because you come, for example, from an administration background, it is highly recommended that you learn these developer skills. They will come in very handy if you need to do some troubleshooting, and you will also learn how to write better code.

Another great feature for beginners in the ISE is the so-called Command Window. You can open it up by either executing the Show-Command cmdlet or pressing the dedicated icon:

It will show you a complete command list, where you can now easily filter the modules and the cmdlets by name. By marking a dedicated cmdlet, its information, the cmdlet parameters and the common parameters are visualized:

This can be a good tool to get familiar with the available cmdlets and their execution. Try to fill in the parameters and use them. Mandatory parameters, for example, for the Remove-ServiceEndpoint cmdlet, are marked with an asterisk.

Another great feature from the PowerShell ISE are the so-called snippets. You can open the snippet list by pressing Ctrl + J:

It brings up a list of available snippets, which can be used to speed up the creation of your script or even just to prevent any manual errors. You can also use them as a learning resource to see how specific tasks can be coded. If you, for example, are not aware of how to code a do...until loop, the snippets will provide you with some initial guidance. For the moment, let's leave it there. Coding techniques and working with snippets will be explained in detail with VSCode later. 

The official Microsoft documentation are evolving continuously and are a great learning resource. If you are not familiar with the PowerShell ISE or just want to increase or check your current knowledge, you should take a look at their content: https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ise/introducing-the-windows-powershell-ise.

Visual Studio Code

As you have seen, the PowerShell ISE is quite a good tool, but still missing some features. Nevertheless, it comes with any Windows environment and is a helpful tool for creating valuable scripts and debugging them, if necessary. In comparison, we will now take an initial look at VSCode and how to set it up for the creation of PowerShell code. An explanation of and the usage of advanced techniques of VSCode will be covered throughout the rest of the book.

Introduction

Visual Studio Code (VSCode) is a lightweight open-source editor, which is free for private and commercial use. Technically, VSCode is built on the framework Electron. Electron is known as a toolset to deploy Node.js applications that are running on the Blink layout engine. The underlying editor is the Monaco Editor. Like the PowerShell ISE, it also has IntelliSense capabilities, which are even available for many more languages. You can easily extend VSCode with the installation of additional extensions