Book Image

PowerShell Core for Linux Administrators Cookbook

By : Prashanth Jayaram, Ram Iyer
Book Image

PowerShell Core for Linux Administrators Cookbook

By: Prashanth Jayaram, Ram Iyer

Overview of this book

PowerShell Core, the open source, cross-platform that is based on the open source, cross-platform .NET Core, is not a shell that came out by accident; it was intentionally created to be versatile and easy to learn at the same time. PowerShell Core enables automation on systems ranging from the Raspberry Pi to the cloud. PowerShell Core for Linux Administrators Cookbook uses simple, real-world examples that teach you how to use PowerShell to effectively administer your environment. As you make your way through the book, you will cover interesting recipes on how PowerShell Core can be used to quickly automate complex, repetitive, and time-consuming tasks. In the concluding chapters, you will learn how to develop scripts to automate tasks that involve systems and enterprise management. By the end of this book, you will have learned about the automation capabilities of PowerShell Core, including remote management using OpenSSH, cross-platform enterprise management, working with Docker containers, and managing SQL databases.
Table of Contents (19 chapters)

Listing the various providers in PowerShell

Before we start preparing for administration using PowerShell, it would be helpful to understand the concept of providers.

How to do it...

To list the providers in PowerShell, follow these steps:

  1. Run pwsh to load PowerShell on the Terminal.
  2. Run the following command:
PS> Get-PsProvider

You will get something that looks like this:

Note the providers that are available in PowerShell, and the drives and capabilities found within these providers.

  1. Navigate to the Alias: drive:
PS> Set-Location Alias:
PS> Get-ChildItem

Note how the prompt is now Alias:

Note the preceding colon after the drive name (Alias: and not Alias). This is necessary for you to indicate to PowerShell that you are switching drives. Without the colon, PowerShell would simply try to look for a directory called Alias in your present working directory.

How it works...

On Linux, PowerShell support is limited (at the time of writing this book). Discussion on the issues pertaining to providers on Linux indicates that further development is highly likely, especially regarding cross-provider support.

A provider is a program that logically represents non-filesystem drives as though they are drives. For instance, on Windows, the Registry is a database of configuration information. In PowerShell 6 on Windows and on Windows PowerShell, the Registry is a provider; this way, administrators can use PowerShell to navigate and manipulate Registry keys in the same way that we work with files. This capability is available on Linux as well, however, there aren't as many providers as there are on Windows.

If you are interested in programming, providers in PowerShell are a great example of the concept of overloading in object-oriented programming.

The Name column gives the names of the providers. Each provider may have one or more drives. For instance, the FileSystem provider in Windows shows all of the partitions (C:, D:, E:, and so on) present on the computer. A Set-Location operation is performed on these drives within the providers, and not the providers themselves. To indicate to PowerShell that you are connecting to a drive and not a subdirectory, the name of the drive must be followed by a colon.

See also

  • The Adding safety switches to functions recipe from Chapter 12, Advanced Concepts of Functions