Prashanth Jayaram

IT Cloud Automation using PowerShell

August 17, 2020 by

Using PowerShell automation, one could easily automate the most common tasks. The future for PowerShell as the automation framework is bright. Shipping PowerShell core on the hybrid platform has opened up new markets, new customers, and new opportunities for Microsoft. At the same time, we still strongly believe in Powershell on Windows Server, Linux and macOS as a great combination for automation.

Let us learn how Powershell is used as the automation toolset for all the Administrators, Developers, and Cloud engineers. Using PowerShell you will rediscover the new ways to automate Cloud tasks. PowerShell offering initially built only to manage the Windows platform. Later, PowerShell becomes the de-facto tool to manage On-Premise and Cloud infrastructures. Microsoft strategically brought an open-sourced version of PowerShell known as PowerShell core and made it available on Windows, Linux, and macOS. Now, it is a one-stop solution to manage cross-platform infrastructures.

Why is PowerShell so important?

PowerShell is a rich collection of libraries built on the .NET Core framework—you can automate practically every aspect of the cloud and on-premise infrastructure. Do you agree? Let us dissect the details.

.Net framework enables PowerShell with a fully-featured command-line shell. PowerShell interactive shell offers a variety of features that make cmdlets are so powerful and efficient command-line tools: command substitution, variable expansion, and more. PowerShell automation becomes a defacto tool to solve most of the infrastructure management.

Why PowerShell cmdlets so easy to use?

Due to its simple construct, we can use it in the way our mind thinks. In addition to traditional programs and operating system commands (CMD.exe), you can also use PowerShell cmdlets. The cmdlets can be created by anyone. The core Microsoft PowerShell team creates the core cmdlets, but many other teams and community-based enthusiasts or specialists are also involved in creating the hundreds of cmdlets that are bundled and shipped to the public repositories. The modules are the functions that take advantage of the facilities built into .Net framework namespace, and therefore are easy to build and write cmdlets. These cmdlets are the building blocks of Powershell automation.

PowerShell introduces a new type of powerful commands, known as cmdlets (pronounced “command-let”) which share a common Verb-Noun syntax. All cmdlets are named in a Verb-Noun pattern, such as Get-Process, Get-Content, Get-Help, Get-AzResourceGroup, Get-VcsUser, and Stop-Process. PowerShell automation can be leveraged to build workflows and apps that help you to build and manage cloud infrastructures.

To check your PowerShell version, run the following command:

PowerShell automation - Get the Powershell version

It is possible to install multiple versions of Azure PowerShell modules. To check the installed Azure PowerShell modules, run the following command:

PowerShell automation modules - List the installed modules

To check Azure CLI modules version and extensions, run the following command:

Powershell Automation Azure CLI modules

To find the loaded module, run the following the command

Powershell Automation Azure CLI modules

By now, you can say that the use of cmdlets is simple and straightforward.

The history of PowerShell

This table data is important to understand the evolution of PowerShell. The matter of the fact that we still use PowerShell 2.0. It doesn’t mean that you need to use PowerShell 2.0. We are using all the way up to PowerShell 7.0. It is recommended to use the latest version of PowerShell. In some cases, it is the developer’s choice or complexity of the process that may lead to the use of the legacy version. The use of different PowerShell version may be based on the preference or maybe perhaps a standard within your company. You should know the features in order to build a good automation task.

Using Powershell automation techniques and ideas, many mundane and repetitive tasks can be automated to allow administrators to focus on more important tasks.

PowerShell

Release Date

OS

Features

PowerShell 1.0

November 2006

Windows XP SP2, Windows Server 2003 SP1 and Windows Vista

PowerShell 1.0 started a new revolution for all the administrators. It’s a major steep to use cmdlets.

PowerShell 2.0

October 2009

Windows 7,

Windows Server 2008, Windows XP with SP3, Windows Server 2003 SP2, and Windows Vista SP1

PowerShell v2 made a breakthrough into the scripting language and hosting API. It in-housed more than 240 new cmdlets.

Remoting, Background jobs and script debugging is the major breakthrough of this release

PowerShell 3.0

September 2012

PowerShell 3.0 integrated with Windows 8 and with Windows Server 2012. Windows 7 SP1, Windows Server 2008 SP1, and Windows Server 2008 R2 SP 1

Job scheduling, integration WinRM service for remoting,

Improved code writing IDE environment, intellisence for auto-detection of cmdlets and more

PowerShell 4.0

October 2013

It is an inbuilt feature of Windows 8.1 and with Windows Server 2012 R2, Windows 7 SP1Windows Server 2008 R2 SP1 and Windows Server 2012

Support for Desired State Configuration (DSC) modules used for build, provision, deploy and manage the configuration of systems.

PowerShel 5.0

February 24, 2016

Windows Management Framework (WMF) 5.0 RTM includes PowerShell 5.0.

Windows 7 SP1,

Windows 8.1,

Windows Server 2012, and

Windows Server 2012 R2

Enhancement DSC modules and support to .Net enumerations and classes.

PowerShell 5.1

August 2, 2016

In built with Windows 10 and

Windows Server 2016.

And

Windows 7 SP1,

Windows 8.1,

Windows Server 2008 R2 SP1,

Windows Server 2012, and

Windows Server 2012 R2

PowerShell 5.1 released in two editions “Desktop version” and “Core version”

This was the last exclusive PowerShell made for the Windows Operating system.

PowerShell Core 6+

August 2016

Windows 10,Windows Server 2008 R2 SP1+,Windows Server 2012,Windows Server 2012 R2,Windows Server 2016, Windows Server 2019, Ubuntu 14.04,Ubuntu 16.04, Ubuntu 17.04,DEbian 8.7, CentOS 7,

RHEL 7, OpenSUSE 42.2, Fedora 25+, macOS 10.12+

Fully cross-platform support on Windows, Linux and macOS.

PowerShell 7

December 3, 2019

Windows 7, 8.1, and 10

Windows Server 2008 R2, 2012, 2012 R2, 2016, and 2019,

macOS 10.13+,

Red Hat Enterprise Linux (RHEL) / CentOS 7+,

Fedora 29+,

Debian 9+,

Ubuntu 16.04+,

openSUSE 15+, and

Alpine Linux 3.8+

PowerShell 7 is the replacement product for PowerShell Core 6.x and Windows PowerShell 5.1—the last supported Windows PowerShell version.

The framework optimized for handling structured data such as JSON, CSV, XML, REST APIs, and object models

What is Automation?

Automation is a process of identifying the routine tasks and define a technique to process or operate the identified tasks automatically. PowerShell automation can save administrators time and effort

Let’s explore some of the most notable benefits.

  • Automation increases productivity by removing manual interventions, human errors, and speeding up the different tasks and processes that are time-intensive and prone to error
  • Automation eliminates unnecessary capital expenditures as it helps develop stable processes that inch towards backups and rollovers, thereby allowing organizations to save more
  • It is easy to adopt automation to standardize processes
  • With automation, we also get faster delivery, mainly because automation ensures repeatability of workflows, processes, protocols, and metrics
  • Risks are greatly reduced with automation as it standardizes processes and increases the validity of workflows
  • Finally, automation also allows for better monitoring by creating real-time reports for measurable metrics like deployment frequency, change-fail-rates, Mean-Time-To-Recover (MTTR), and lead-time for changes

Let us deep-dive into the details to understand more about the PowerShell automation. For example, the Azure automation framework is used to manage the IT Cloud infrastructure efficiently and effectively. In our environment, the Test or Dev VMs are stopped and started automatically on a scheduled basis. This will have a direct impact on reducing costs.

To run a maintenance job on Azure SQL Databases, we may opt for Azure automation. We can use the template to standardize the process.

It is easy to integrate PowerShell Azure CLI commands in Bash scripting this makes life easier for Linux administrators to manage Azure Cloud platform.

Monitoring and alerting, you can use Get-AzMetricDefinition -ResourceId <Resource ID> cmdlet to get into the details of all the metrics.

  • Note: Azure provides a more sophisticated way to monitor the Cloud resources using Log Analytics

Wrap up

This article has provided a whistle-stop tour of the benefits PowerShell brings to the table. We’ve looked at the philosophies and guiding principles behind PowerShell. I will discuss more about the creation and development of PowerShell automation, as well as the tradeoffs Linux administrators made when implementing the automation ideas to manage Cloud infrastructure. We’ve also looked at some of the key terms used in the article. Stay tuned to get more updates in this series on PowerShell automation.

Table of contents

IT Cloud Automation using PowerShell
Deep dive into IT Cloud Automation using PowerShell
Getting started with Azure Automation
Getting started with Azure SQL Database using Azure CLI
Provisioning SQL Server 2019 Azure Container Instance using PowerShell
Four different methods to copy your Azure SQL database
Azure SQL Database vs SQL Server on Azure VMs
How to provision Azure SQL Database using Ansible
Quick start guide to Geo-restore in Azure SQL Database
Different ways to login to Azure automation using PowerShell
How to perform Azure SQL database Import/Export operations using PowerShell
How to set up Azure Data Sync between Azure SQL databases and on-premises SQL Server
Prashanth Jayaram
PowerShell

About Prashanth Jayaram

I’m a Database technologist having 11+ years of rich, hands-on experience on Database technologies. I am Microsoft Certified Professional and backed with a Degree in Master of Computer Application. My specialty lies in designing & implementing High availability solutions and cross-platform DB Migration. The technologies currently working on are SQL Server, PowerShell, Oracle and MongoDB. View all posts by Prashanth Jayaram

168 Views