Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying PowerShell Core for Linux Administrators Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
PowerShell Core for Linux Administrators Cookbook

PowerShell Core for Linux Administrators Cookbook

By : Prashanth Jayaram , Ram Iyer
close
close
PowerShell Core for Linux Administrators Cookbook

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)
close
close

Introduction

Carl Sagan once said the following:

If you are skeptical, then no new ideas will make it through to you. You will never learn anything new. You become a crotchety old person convinced that nonsense is ruling the world. (There is, of course, much data to support you.) But every now and then, maybe once in a hundred cases, a new idea turns out to be on the mark, valid, and wonderful. If you are too much in the habit of being skeptical about everything, you are going to miss or resent it, and … you will be standing in the way of understanding and progress.

Us system administrators start building our arsenal of administration tools from the very first day. Usually, we do not think of adding tools to do something that our favorite already does—this would be like adding a redundant weapon. However, these alternate tools turn out to be great. PowerShell, to me, was one such tool.

There is a good chance that you are reading this page at a bookstore—digital or physical—and there is a good chance that the question in your mind is, Is this book for me?

The answer is probably yes, if you are any of the following:

  • A Linux administrator, open to other scripting frameworks
  • A system administrator who manages Linux as well as Windows workloads, looking to unify management
  • A Linux administrator who wants a framework that handles—and aces in—structured data (as a side note, PowerShell is probably the only framework in Linux that works well with structured data)
  • A Windows Administrator, new to PowerShell, wanting to learn PowerShell scripting
  • A generally curious system administrator

A brief note on .NET Core

Microsoft's announcement of open sourcing .NET in 2014 almost stirred a storm. Many rushed to the stands (so to speak) to read about the unbelievable—how could Microsoft possibly open source the core of their operating system? Some were cynical, while others rejoiced. Then came the announcementa little louder and clearerthat .NET Core was open source, not the .NET Framework. Many said that .NET Core was a subset of .NET Framework.

.NET was first announced in 2000, as a new platform based on internet standards. Along with it, by the end of the year, Microsoft published the Common Language Infrastructure as a standard, so that anyone who wanted could write their own .NET framework based on those standards. .NET Framework has been the basis of Windows since the noughties.

Windows PowerShell was released to the general market in 2006, as an implementation of .NET Framework, and focused on system administrators (or sysadmins), enabling them to better manage their workloads or daily activities and automate them. PowerShell 1.0 was leaps and bounds ahead of the hitherto rulers of automation Windows: Batch and VBScript.

In June, 2016, Microsoft released a collaboratively refactored, more modern and efficient .NET. The .NET Core was officially born. While .NET Framework continues to rule the Windows arena, .NET Core, which is open source and cross-platform, has picked up great momentum and grows every day. .NET Core seems to be the way forward.

PowerShell Core is based on .NET Core, and therefore is open source, with the same vision as .NET Core: to be cross-platform.

The assumptions

This book assumes no experience in PowerShell, and so sticks to the basic and intermediate levels. That is to say, we will not create complex PowerShell modules in this book. We will start by installing PowerShell, understanding the object model, working through scripting by understanding PowerShell constructs, creating functions, creating simple script modules, and so on, as system administrators (and not as programmers). We will also learn how to manage Docker and cloud workloads using PowerShell.

How to read this book

You may skip recipes or even chapters. Whenever there is a need for something we created in a recipe that you have skipped, we will mention the recipe in the prerequisites. For example, we will state something similar to the following: follow the How to do it… section of the skipped recipe to fulfill this prerequisite.

An important note

There are two editions of PowerShell available today:

  1. Windows PowerShell (up to v5.1, proprietary; powershell)
  2. PowerShell Core (6.0+, open source; pwsh)

Windows PowerShell is based on .NET Framework, which is Microsoft's proprietary framework that Windows is built on. PowerShell began at 1.0, and was considered feature-complete at 5.1. Microsoft has stopped developing Windows PowerShell; going forward, it will only receive bug fixes.

The open source PowerShell Core 6.0 is based on the open source .NET Core. This book is about open source PowerShell. Windows PowerShell and PowerShell Core are two different entities, with two different code bases.

While PowerShell to a Windows administrator has so far meant Windows PowerShell, officially, PowerShell now means the open source PowerShell Core. In this book, we follow this convention: going forward, every mention of PowerShell points to the open source PowerShell Core 6. Windows PowerShell is referred to as Windows PowerShell.

Writing the cmdlets (Linux admins note)

If you are a Linux administrator, chances are, you do not like long commands—verbosity, to be specific. We will try to make the commands as short as possible, but in the interest of readability (which is an important convention in PowerShell), we will also mention the full commands.

Tab completion comes in handy for reducing keystrokes. PowerShell tab-completes cmdlets, parameters, and in many cases, even parameter values. We will learn about this in the Running cmdlets with minimal keystrokes section of Chapter 2, Preparing for Administration Using PowerShell.

In general, we split scripting from running cmdlets on the console in the following ways:

  • By using aliases (carefully) and short parameter names at the Terminal to save keystrokes and time
  • By being verbose in scripts, so that everyone using them can read and understand them

Off we go

This is where it all starts: with the installation of PowerShell on your system. The installation of PowerShell is simple and straightforward. Since PowerShell is open source, its source code is available on GitHub. At the moment, Windows, Debian (and Ubuntu), Red Hat Linux (and CentOS), Fedora, OpenSUSE, and macOS are officially supported by the PowerShell project. Arch Linux and Kali Linux are supported by the community, as indicated in the README project. Community support is also available for the Snapcraft edition of PowerShell, which can be used on many of the modern-day Linux distributions.

PowerShell 6, at the time of writing this book, is experimentally available for Raspbian Stretch as well as the ARM edition of Windows (https://github.com/PowerShell/PowerShell/blob/master/README.md).

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY