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

Classes 


With version 5, classes have been introduced to PowerShell. If you are coming from a developer background, you may already be familiar with classes. A class is a data structure for storing properties and methods. Classes in PowerShell, though, have some limitations and are very rarely used. The most common use case is their implementation for the Desired State Configuration, which we will dive into in a later chapter. Therefore, we will give you only a short introduction to classes, and provide further links and material that you can have a look at.

The creation of a simple class starts with the class keyword. The class description is like a model. Think of it as a recipe for a fantastic PowerShell cake. It can be used to create hundreds of cakes.

You should always add a constructor to the class. A constructor is the first code that will be executed, and is always named the same as the class itself.

The first example is very straightforward:

#Class with constructor
class FantasticPowerShellCake...