ENGLISH

PowerShell Core for Linux Administrators Cookbook: Use PowerShell Core 6.x on Linux to automate complex, repetitive, and time-consuming tasks

Book information

Publisher
Packt Publishing
Year
2018
ISBN
9781789137231
Language
english
Format
PDF
Filesize
27 MB (28496009 bytes)
Edition
1
Pages
566\554
Time added
2020-05-22 19:00:39

Description

Over 150 recipes to leverage Microsoft's open source automation framework and command line shell Key FeaturesWork effectively on Windows, Linux, and macOS with PowerShell’s object-oriented approach and capabilitiesGenerate rich insights into your Linux workloads to help remediate any issuesEnhance your native Linux capabilities with PowerShell Core 6.1Book Description 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. What you will learnLeverage the object model of the shell, which is based on .NET CoreAdminister computers locally as well as remotely using PowerShell over OpenSSHGet to grips with advanced concepts of PowerShell functionsUse PowerShell for administration on the cloudKnow the best practices pertaining to PowerShell scripts and functionsExploit the cross-platform capabilities of PowerShell to manage scheduled jobs, Docker containers and SQL DatabasesWho this book is for PowerShell Core 6.1 Linux Administration Cookbook is for you if you are a system administrator who wants to learn to control and automate a Linux environment with PowerShell Core 6.1. Basic knowledge of PowerShell scripting is necessary. It is assumed that you already understand how an operating system is structured and how to use the command-line interface to work with the operating system. Table of ContentsIntroducing PowerShell CorePreparing for Administration using PowerShellFirst Steps in Administration using PowerShellPassing data through pipelinesUsing Variables and ObjectsWorking with StringsFlow Control using Branches and LoopsPerforming Calculations Using Arrays and Hash Tables Handling Files and Directories Building Scripts and FunctionsAdvanced Concepts of Functions Debugging and Error Handling Enterprise Administration using PowerShell PowerShell and Cloud OperationsUsing PowerShell for SQL Database Management Using PowerShell with Docker Cover Title Page Copyright and Credits Dedication About Packt Contributors Table of Contents Preface Chapter 1: Introducing PowerShell Core Introduction A brief note on .NET Core The assumptions How to read this book An important note Writing the cmdlets (Linux admins note) Off we go Installing PowerShell Getting ready How to do it… Installation on Ubuntu Installing from the repository Installing via direct download Installation on CentOS Installing from the repository Installing via direct download Using the Snapcraft package Using the binary archives Bonus– using the Install-PowerShell script (including on macOS) How it works… See also Updating and using Help Getting ready How to do it… How it works… See also Exploring about_ topics Getting ready How to do it… How it works… Discovering cmdlets How to do it… How it works… Finding and installing PowerShell modules How to do it… How it works… There's more… See also Listing the various providers in PowerShell How to do it… How it works… See also Understanding objects How to do it… How it works… There's more… See also Parsing input from text to object Getting ready How to do it… How it works… There's more… See also Comparing the outputs of Bash and PowerShell Getting ready How to do it… How it works… See also Comparing Windows PowerShell and PowerShell Core Support for snap-ins Convenience aliases PowerShell Workflows PowerShell Desired State Configuration Working with aliases How to do it… How it works… There's more… See also Dissecting a .NET Core object Getting ready How to do it… How it works… See also Listing out the execution policies and setting a suitable one Getting ready How to do it… How it works… See also Chapter 2: Preparing for Administration Using PowerShell Introduction Installing Visual Studio Code Getting ready How to do it… How it works… See also Configuring automatic variables Getting ready How to do it… How it works… Changing shell behavior using variables Getting ready How to do it… How it works… See also Enabling automated execution of commands for each load Getting ready How to do it… How it works… There's more… Customizing the Terminal prompt Getting ready How to do it… How it works… There's more… See also Understanding standard redirection in PowerShell How to do it… How it works… Out-File Tee-Object Accepting input from a file There's more… See also Calling native Linux commands from PowerShell Getting started How to do it… How it works… See also Understanding cmdlets and parameters Getting ready How to do it… How it works… There's more… Running cmdlets with minimal keystrokes Getting ready How to do it… How it works… There's more… Finding parameter aliases Getting ready How to do it… How it works… Calling a PowerShell script Getting ready How to do it… How it works… Dot-sourcing a PowerShell script How to do it… How it works… There's more… Calling a PowerShell cmdlet from outside of PowerShell How to do it… How it works… Recording the cmdlets run on the PowerShell console How to do it… How it works… Chapter 3: First Steps in Administration Using PowerShell Introduction Working with date properties Getting ready How to do it… How it works… See also Working with date and time methods How to do it… How it works… Working with currently-running processes to measure resource consumption How to do it… How it works… Launching and stopping a process Getting ready How to do it… How it works… Finding the owner of a process How to do it… How it works… There's more… See also Invoking an application based on the file type How to do it… How it works… Installing the CronTab PowerShell module How to do it… How it works… Scheduling jobs in PowerShell Getting ready How to do it… How it works… Removing scheduled jobs in PowerShell How to do it… How it works… See also Chapter 4: Passing Data through the Pipeline Introduction Selecting columns from the output Getting ready How to do it… How it works… There's more… See also Limiting the number of output objects Getting ready How to do it… How it works… Expanding the properties within properties How to do it… How it works… Filtering objects Getting ready How to do it… How it works… There's more… Grouping the output How to do it… How it works… There's more… See also Sorting the output How to do it… How it works… Taking actions on the returned objects Getting ready How to do it… How it works… Understanding pipeline-enabled parameters How to do it… How it works… Importing content into PowerShell How to do it… How it works… Chapter 5: Using Variables and Objects Introduction Using environment variables  How to do it… How it works… There's more… See also Storing the output of an instance of a .NET Core object Getting ready How to do it… How it works… See also Adding custom properties to an object How to do it… How it works… See also Creating a custom object from a returned object How to do it… How it works… See also Understanding the extension of type data Getting ready How to do it… How it works… See also Retaining object modifications across sessions Getting ready How to do it… How it works… See also Removing custom type data How to do it… How it works… See also Understanding variables Chapter 6: Working with Strings Introduction Creating a literal string How to do it… How it works… Creating an expanding string Getting ready How to do it… How it works… Understanding Here-Strings How to do it… How it works… Using basic string methods Getting ready How to do it… How it works… See also Performing string matching operations How to do it… How it works… There's more… Replacing substrings within strings How to do it… How it works… There's more… Splitting and combining strings How to do it… How it works… Using the formatting operator How to do it… How it works… There's more… Chapter 7: Flow Control Using Branches and Loops Introduction Using If–ElseIf–Else conditions to control script flow Getting ready How to do it… How it works… Using Switch–Case conditions to control script flow How to do it… How it works… Learning to use delays How to do it… How it works… Writing a basic looping construct How to do it… How it works… Writing a more complex loop on a predefined array How to do it... How it works… Using the For loop construct How to do it… How it works… Using the While loop construct How to do it… How it works… Cleaning empty directories using the Do–While construct Getting ready How to do it… How it works… See also Cleaning empty directories using the Do–Until construct Getting ready How to do it… How it works… Chapter 8: Performing Calculations Introduction Performing arithmetic operations Getting ready How to do it… How it works… See also Performing calculations on the output Getting ready How to do it How it works… There's more… Working with administrative constants Getting ready How to do it… How it works… Working with calculated properties Getting ready How to do it… How it works… Working with binary numbers How to do it… How it works… Performing base conversions How to do it… How it works… There's more… Chapter 9: Using Arrays and Hashtables Introduction Creating and working with a simple array How to do it… How it works… There's more… Accessing and manipulating array items How to do it… How it works… There's more… See also Sorting an array How to do it… How it works… There's more… See also Searching for an item in an array How to do it How it works… See also Combining arrays How to do it… How it works… Item matching in an array How to do it… How it works… There's more… Removing elements from an array How to do it… How it works… Comparing arrays How to do it… How it works… Creating a simple hashtable How to do it… How it works… Performing simple tasks on a hashtable How to do it… How it works… Chapter 10: Handling Files and Directories Introduction Reading content from a file How to do it… How it works… See also Sending output to a file Getting ready… How to do it… How it works… See also Adding and setting content to a file Getting ready How to do it… How it works… Searching for content Getting ready How to do it… How it works… Working with locations How to do it… How it works… See also Working with files and directories How to do it… How it works… There's more… Listing files and directories How to do it… How it works… There's more… Working with structured and unstructured files How to do it… How it works… There's more… Chapter 11: Building Scripts and Functions Introduction Writing a simple script How to do it… How it works… Reading input from the host How to do it… How it works… Displaying an interactive menu How to do it… How it works… See also Showing progress of execution How to do it… How it works… See also Defining arguments for a script How to do it… How it works… Writing a simple function How to do it… How it works… See also Working with a script block How to do it… How it works… Measuring running duration How to do it… How it works… See also Important points to remember Using Host cmdlets Returning objects from functions Naming functions Chapter 12: Advanced Concepts of Functions Introduction Defining parameters Getting ready How to do it… How it works… There's more… See also Working with parameter aliases How to do it… How it works… Working with parameter sets How to do it… How it works… Adding default values to the parameter How to do it… How it works… Adding validation to parameter input How to do it… How it works… Handling dependencies and prerequisites How to do it… How it works… Adding safety switches to functions How to do it… How it works… Adding help to functions How to do it… How it works… Adding support for pipeline input How to do it… How it works… There's more… Using the Main function How to do it… How it works… Writing a script module How to do it… How it works… See also Handling module cleanup How to do it… How it works… Chapter 13: Debugging and Error Handling Introduction The Debug tab of Visual Studio Code Writing debug output Getting ready How to do it… How it works… Running a script in Debug mode How to do it… How it works… Tracing errors How to do it… How it works… Using breakpoints How to do it… How it works… Using conditional breakpoints How to do it… How it works… Using exit codes How to do it… How it works… Working with the Error variable How to do it… How it works… Controlling flow based on errors How to do it… How it works… See also Sending verbose output to a file How to do it… How it works… Chapter 14: Enterprise Administration Using PowerShell Introduction to OpenSSH Installing OpenSSH on Windows Getting ready How to do it… How it works… There's more… See also Configuring OpenSSH using sshd_config on Windows Getting ready How to do it… How it works… There's more… Installing and configuring OpenSSH on Linux Getting ready How to do it… How it works… There's more… See also Testing PowerShell remoting using OpenSSH Getting ready How to do it… How it works… Testing PowerShell remoting with OpenSSH using keys between Linux machines Getting ready How to do it… How it works… There's more… Testing PowerShell remoting with OpenSSH using keys between Linux and Windows machines Getting ready How to do it… How it works… See also Running cmdlets on remote computers Getting ready How to do it… How it works… Managing the administration of remote machines with PowerShell Jobs Getting ready How to do it… How it works… There's more… Generating HTML reports Getting ready How to do it... How it works… See also Sending email messages Getting ready How to do it… How it works… Chapter 15: PowerShell and Cloud Operations Introduction to PowerShell for Cloud operations on Azure and AWS Installation of the AzureRM.Netcore PowerShell module on Linux machines Getting ready How to do it… How it works… There's more... Installation of the AWSPowerShell.NetCore module on Linux machines Getting ready How to do it… How it works… There's more… Discovering AzureRM cmdlets discovery functions How to do it… How it works… Azure Cloud Shell in action Getting ready How to do it… How it works… See also Provisioning a Ubuntu 18.04 LTS VM using AzureRM.Netcore cmdlets on the Azure Cloud Getting ready How to do it… How it works… There's more… Provisioning Linux Docker containers using Docker Machine on Azure Getting ready How to do it… How it works… There's more… See also Provisioning Linux VM using PowerShell script  Getting ready How to do it… How it works… There's more… Performing management tasks using ARM PowerShell cmdlets Getting ready How to do it… How it works… PowerShell remoting to Azure VM using OpenSSH Getting ready How to do it… How it works… Managing AWS credentials Getting ready How to do it… How it works… There's more… See also Connecting an EC2 Linux instance using SSH from PowerShell Getting ready How to do it… How it works… Chapter 16: Using PowerShell for SQL Database Management Introduction to PowerShell, SQL Server, and Python Technical requirements Installing .Net Core on Linux Getting ready How to do it… How it works… There's more... See also Installing the SqlServer module  Getting ready How to do it… How it works… There's more… See also Overview of SQL Server SMO  How to do it… See also Running cross-platform T-SQL queries Getting ready How to do it… How it works… Running cross-platform T-SQL queries on multiple servers Getting ready How to do it… How it works… See also Creating a repository for Get-Process in the SQL database Getting ready How to do it… How it works... Data formatting examples with PowerShell Getting ready How to do it… How it works… Overview of PowerShell, Bash, and Python integration Getting ready How to do it… How it works… Chapter 17: Using PowerShell with Docker Introduction to Docker Installation of Docker on Linux Getting ready How to do it… How it works… See also Getting and listing the Docker management cmdlets Getting ready How to do it… How it works… See also Overview of Docker Hub and its operations Getting ready How to do it… How it works… See also Building an image from a Dockerfile using PowerShell Getting ready How to do it… How it works… See also Pulling a Docker container image from the repository Getting ready How to do it… How it works… Listing Docker containers and the images  How to do it… How it works… Starting and stopping Docker containers Getting ready How to do it… How it works… Removing containers and container images How to do it… How it works… Working with a container using miscellaneous Docker PowerShell cmdlets How to do it… How it works… See also Running a PowerShell script to set up Docker containers How to do it… How it works… Finding Docker tags using PowerShell cmdlets from the remote registry How to do it… How it works… See also Other Books You May Enjoy Index

Similar books