Book description
Use PowerShell 6.0 on Linux to automate complex, repetitive, and time consuming tasks
About This Book
- Understand PowerShell's object-oriented approach, and truly cross-platform capabilities, which work equally well on Windows, Linux and macOS.
- Extend your OMS capabilities to get rich insights about your Linux workloads to quickly remediate any issues.
- A recipe-based guide that will enhance your native Linux capabilities with PowerShell 6.0.
Who This Book Is For
If you are system administrator who wants to learn to control and automate your Linux environment with PowerShell 6.0 then, this book is for you. Basic knowledge of PowerShell scripting would be necessary. Very basic knowledge required with respect to how an operating system is structured and how to use the command line interface to work with the operating system.
What You Will Learn
- Understand the fundamentals of .NET Core and PowerShell
- Understand the advanced concepts of .NET Core and PowerShell
- Learn to write PowerShell scripts and functions with the best practices in mind
- Take a deep dive into administering computers locally as well as remotely using PowerShell
- Use PowerShell for advanced administration such as on the Cloud, Docker containers, VMware and SQL Server
In Detail
PowerShell is an implementation of .NET Core. .NET Core is a cross-platform open source management framework, which adheres to POSIX standards and makes available API calls that work well with all of the major operating systems: Windows, Linux and macOS. .NET Core for Linux has been a success, because of its adherence to standards, as well as for its lightweight implementation. PowerShell extends the capabilities towards management of Linux servers as well as using containerizers such as Docker.
This book will include real-world examples on how you can use core PowerShell functions to effectively administer Linux-based systems and environments. Later, this book will cover interesting recipes on how system administrators can make use of PowerShell 6.0 to quickly automate complex, repetitive and time-consuming tasks. This book will also teach you to develop scripts to automate tasks that involve systems and enterprise management. By the end of this book, you will also understand your OMS automation capabilities to apply, monitor, and update configurations, gaining real-time visibility into your Linux workloads to quickly get it resolved.
Style and approach
With a recipe-based approach, we will help you take advantage of PowerShell 6.0 to call all native Linux capabilities to automate your environment.
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- About Packt
- Contributors
- Preface
-
Introducing PowerShell Core
- Introduction
- Installing PowerShell
- Updating and using Help
- Exploring about_ topics
- Discovering cmdlets
- Finding and installing PowerShell modules
- Listing the various providers in PowerShell
- Understanding objects
- Parsing input from text to object
- Comparing the outputs of Bash and PowerShell
- Comparing Windows PowerShell and PowerShell Core
- Working with aliases
- Dissecting a .NET Core object
- Listing out the execution policies and setting a suitable one
-
Preparing for Administration Using PowerShell
- Introduction
- Installing Visual Studio Code
- Configuring automatic variables
- Changing shell behavior using variables
- Enabling automated execution of commands for each load
- Customizing the Terminal prompt
- Understanding standard redirection in PowerShell
- Calling native Linux commands from PowerShell
- Understanding cmdlets and parameters
- Running cmdlets with minimal keystrokes
- Finding parameter aliases
- Calling a PowerShell script
- Dot-sourcing a PowerShell script
- Calling a PowerShell cmdlet from outside of PowerShell
- Recording the cmdlets run on the PowerShell console
-
First Steps in Administration Using PowerShell
- Introduction
- Working with date properties
- Working with date and time methods
- Working with currently-running processes to measure resource consumption
- Launching and stopping a process
- Finding the owner of a process
- Invoking an application based on the file type
- Installing the CronTab PowerShell module
- Scheduling jobs in PowerShell
- Removing scheduled jobs in PowerShell
- Passing Data through the Pipeline
-
Using Variables and Objects
- Introduction
- Using environment variables
- Storing the output of an instance of a .NET Core object
- Adding custom properties to an object
- Creating a custom object from a returned object
- Understanding the extension of type data
- Retaining object modifications across sessions
- Removing custom type data
- Understanding variables
- Working with Strings
-
Flow Control Using Branches and Loops
- Introduction
- Using If–ElseIf–Else conditions to control script flow
- Using Switch–Case conditions to control script flow
- Learning to use delays
- Writing a basic looping construct
- Writing a more complex loop on a predefined array
- Using the For loop construct
- Using the While loop construct
- Cleaning empty directories using the Do–While construct
- Cleaning empty directories using the Do–Until construct
- Performing Calculations
-
Using Arrays and Hashtables
- Introduction
- Creating and working with a simple array
- Accessing and manipulating array items
- Sorting an array
- Searching for an item in an array
- Combining arrays
- Item matching in an array
- Removing elements from an array
- Comparing arrays
- Creating a simple hashtable
- Performing simple tasks on a hashtable
- Handling Files and Directories
- Building Scripts and Functions
-
Advanced Concepts of Functions
- Introduction
- Defining parameters
- Working with parameter aliases
- Working with parameter sets
- Adding default values to the parameter
- Adding validation to parameter input
- Handling dependencies and prerequisites
- Adding safety switches to functions
- Adding help to functions
- Adding support for pipeline input
- Using the Main function
- Writing a script module
- Handling module cleanup
- Debugging and Error Handling
-
Enterprise Administration Using PowerShell
- Introduction to OpenSSH
- Installing OpenSSH on Windows
- Configuring OpenSSH using sshd_config on Windows
- Installing and configuring OpenSSH on Linux
- Testing PowerShell remoting using OpenSSH
- Testing PowerShell remoting with OpenSSH using keys between Linux machines
- Testing PowerShell remoting with OpenSSH using keys between Linux and Windows machines
- Running cmdlets on remote computers
- Managing the administration of remote machines with PowerShell Jobs
- Generating HTML reports
- Sending email messages
-
PowerShell and Cloud Operations
- Introduction to PowerShell for Cloud operations on Azure and AWS
- Installation of the AzureRM.Netcore PowerShell module on Linux machines
- Installation of the AWSPowerShell.NetCore module on Linux machines
- Discovering AzureRM cmdlets discovery functions
- Azure Cloud Shell in action
- Provisioning a Ubuntu 18.04 LTS VM using AzureRM.Netcore cmdlets on the Azure Cloud
- Provisioning Linux Docker containers using Docker Machine on Azure
- Provisioning Linux VM using PowerShell script
- Performing management tasks using ARM PowerShell cmdlets
- PowerShell remoting to Azure VM using OpenSSH
- Managing AWS credentials
- Connecting an EC2 Linux instance using SSH from PowerShell
-
Using PowerShell for SQL Database Management
- Introduction to PowerShell, SQL Server, and Python
- Technical requirements
- Installing .Net Core on Linux
- Installing the SqlServer module
- Overview of SQL Server SMO
- Running cross-platform T-SQL queries
- Running cross-platform T-SQL queries on multiple servers
- Creating a repository for Get-Process in the SQL database
- Data formatting examples with PowerShell
- Overview of PowerShell, Bash, and Python integration
-
Using PowerShell with Docker
- Introduction to Docker
- Installation of Docker on Linux
- Getting and listing the Docker management cmdlets
- Overview of Docker Hub and its operations
- Building an image from a Dockerfile using PowerShell
- Pulling a Docker container image from the repository
- Listing Docker containers and the images
- Starting and stopping Docker containers
- Removing containers and container images
- Working with a container using miscellaneous Docker PowerShell cmdlets
- Running a PowerShell script to set up Docker containers
- Finding Docker tags using PowerShell cmdlets from the remote registry
- Other Books You May Enjoy
Product information
- Title: PowerShell Core for Linux Administrators Cookbook
- Author(s):
- Release date: November 2018
- Publisher(s): Packt Publishing
- ISBN: 9781789137231
You might also like
book
Windows Server 2012 Automation with PowerShell Cookbook
If you work on a daily basis with Windows Server 2012, this book will make life …
book
PowerShell Fast Track: Hacks for Non-Coders
Create complex scripts in PowerShell and learn how to connect them to cloud services like Azure …
book
Troubleshooting Windows Server with PowerShell
This book shows you how to use PowerShell to quickly pinpoint, diagnose, and solve problems with …
book
Windows PowerShell for Developers
Want to perform programming tasks better, faster, simpler, and make them repeatable? Take a deep dive …