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

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 10Creating 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 12PowerShell 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 13Working with Windows, concentrates on the components of PowerShell that Windows administrators can leverage to maintain, troubleshoot, and tune their Windows operating system.

Chapter 14Working 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 15Connecting 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 17PowerShell 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:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. 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."

Note

Warnings or important notes appear like this.

Note

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.