Book Image

Powershell Core 6.2 Cookbook

By : Jan-Hendrik Peters
Book Image

Powershell Core 6.2 Cookbook

By: Jan-Hendrik Peters

Overview of this book

This book will follow a recipe-based approach and start off with an introduction to the fundamentals of PowerShell, and explaining how to install and run it through simple examples. Next, you will learn how to use PowerShell to access and manipulate data and how to work with different streams as well. You will also explore the object model which will help with regard to PowerShell function deployment. Going forward, you will get familiar with the pipeline in its different use cases. The next set of chapters will deal with the different ways of accessing data in PowerShell. You will also learn to automate various tasks in Windows and Linux using PowerShell Core, as well as explore Windows Server. Later, you will be introduced to Remoting in PowerShell Core and Just Enough Administration concept. The last set of chapters will help you understand the management of a private and public cloud with PowerShell Core. You will also learn how to access web services and explore the high-performance scripting methods. By the end of this book, you will gain the skills to manage complex tasks effectively along with increasing the performance of your environment.
Table of Contents (14 chapters)

Variable scoping

Scopes are important in your day-to-day scripting and they control the visibility of your variables, functions, and aliases. While PowerShell does a great job of handling scopes automatically in a way that feels very natural to the user, you can also use scopes implicitly in your scripts.

How to do it...

Install and start PowerShell Core and execute the following steps:

  1. Execute the following code block:
$outerScope = 'Variable outside function'

function Foo
{
Write-Host $outerScope
$outerScope = 'Variable inside function'
Write-Host $outerScope
}

Foo
Write-Host $outerScope

You should see the following output:

  1. Modify the code a little bit to use scope modifiers like private, script...