Skip to main content

Cross-Platform PowerShell in Azure

Course

Intro Video

Photo of Chad Crowell

Chad Crowell

DevOps Training Architect II in Content

Chad currently resides in Austin, Texas where he loves trying local food trucks with his wife and 3-year-old daughter. He was first introduced to the concept of personal development through Jim Rohn back in 2008. This entrepreneur’s unique outlook gave Chad a new perspective and the power to change the trajectory of his life forever. Chad continues to use these philosophies in his work at Linux Academy and hopes to spread his message of personal betterment to anyone that views his content.

Length

12:00:00

Difficulty

Intermediate

Videos

12

Hands-on Labs

10

Course Details

Version 6 of PowerShell has gone cross-platform! That means you can run PowerShell on both Windows and Linux. Commonly referred to as PowerShell Core, version 6 is built on top of the .NET Core Runtime 2.0 and is completely open source. In this course, you can expect to become familiar with running PowerShell Core on Linux. In the first part of the course, we'll go through commands and scripting, and, in subsequent lessons, move on to using the Az module and provisioning resources in Azure.

The prerequisites for this course include:

Azure PowerShell Essentials Microsoft Azure Fundamentals

Syllabus

Introduction

Course Overview

00:02:04

Lesson Description:

Here is a brief overview of the course and what you can expect to learn in this course

About the Training Architect

00:00:29

Lesson Description:

A little about the Training Architect of this course!

About the Interactive Diagram

00:02:39

Lesson Description:

The interactive diagram will be your course guide and we will use it in each lesson. Here's how to use it and navigate throughout.

Getting Started with PowerShell Core

The Power of PowerShell

00:13:18

Lesson Description:

In this lesson, we introduce PowerShell Core and go over some fundamental parts of the commands. We also demonstrate installing PowerShell Core on both Windows and Linux.

Commands and Scripting

00:17:39

Lesson Description:

In this lesson, we cover some basic commands and how to filter and pipeline those commands to output only the items you want. Also, we go over how to create a script with here-strings and run the script to return an output of variables. Finally, we show how to create a PowerShell remote session using the New-PSSession cmdlet.Install OpenSSH on Windows ServerPowerShell Commands used in This Lesson

Get-ChildItem -Path /tmp -Name`

Get-Help Format-Table`

Get-Command -ParameterName *Auth* -ParameterType AuthenticationMechanism`

Set-Location /tmp`

Get-Alias -Name gp*, sp* -Exclude *ps`

Get-Process | Where-Object {$_.WorkingSet -gt 2kb}`

Get-ChildItem | Where-Object Length -gt 1kb | out-file ./items.csv

Get-Content ./items.csv
PowerShell Scripts Used in This Lesson
$FirstName='Chad'
$LastName='Crowell'
$UserID=$Firstname+'.'+$Lastname
$PhoneNumber='555-555-5555'
$Website='https://linuxacademy.com'
$TemporaryPassword=GET-RANDOM

$WelcomeLetter=@"
Hello and welcome to Linux Academy $FirstName !

Your user id will be $UserID with a Temporary Password of $TemporaryPassword
and our Website is $Website. We can be reached at $PhoneNumber.

Thanks!
Linux Academy Support Team
"@

$WelcomeLetter

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

00:45:00

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

00:45:00

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

00:45:00

PowerShell Core in Azure

Azure PowerShell Az Module

00:13:50

Lesson Description:

In this lesson, we cover how to install the Az module, which allows you to interface with your Azure resources. We also discuss the AzureRM module and the differences between Az and AzureRM modules. Commands Used in This Lesson

Install-Module -Name Az -AllowClobber -Scope CurrentUser

Install-Module -Name Az -AllowClobber -Force

Get-InstalledModule -Name Az -AllVersions

Uninstall-AllModules -TargetModule Az -Version 0.7.0 -Force

Uninstall-AzureRm

Get-InstalledModule -Name AzureRM -AllVersions

Enable-AzureRmAlias -Scope CurrentUser

Get-Command -Verb Get -Noun AzVM* -Module Az.Compute

Get-Command -Verb Get -Noun AzResource* -Module Az.Resources

Get-Command -Verb Get -Noun AzStorage* -Module Az.Storage

Get-Command -Verb Get -Noun AzKeyVault* -Module Az.KeyVault

Get-Command -Verb Get -Noun AzWebApp* -Module Az.Websites

Get-Command -Verb Get -Noun AzSql* -Module Az.Sql
Helpful LinksAz Module Az versus AzureRM Cloud Shell Create a Key Vault Create a Container Create a VM Create a Storage Account Create an App Service Plan Create a Web App Create a Service Principal

Different Shells for Different Spells

00:07:18

Lesson Description:

In this lesson, we explain the controversy around Bash versus PowerShell and set the record straight (hint: it's not really a comparison). We also demonstrate the ability for PowerShell to treat the output as an object and not a string. We will cover basic arrays, loops, and functions. Commands Used in This Lesson

$commands = Get-Command

Set-Location variable:

$z = 0

Get-ChildItem
String Interpolation
$items = (Get-ChildItem).Count
"There are $items items in the folder"
An Array
$array = "Chad", "Crowell"
$array[0]
A Loop
for ($i = 0; $i -le 5; $i++)
{
    "`$i = $i"
}
A Function
function Write-HelloWorld()
{
    'Hello World'
}
Write-HelloWorld

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

00:45:00

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

01:00:00

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

01:00:00

Manage Identities

Authentication Methods

00:07:14

Lesson Description:

In this lesson, we discuss the authentication methods for PowerShell. You may want to limit access for PowerShell and pass a service principal instead of a traditional user account. This will follow the least-priviledge best practice of the cloud and will not expose any unnecessary secrets to unauthorized participants. Helpful LinksManaged Identity Service Principal Signing in with PowerShell and Service Principal

Service Principals

00:09:32

Lesson Description:

In this lesson, we demonstrate how to create a service principal with certificate- and password-based authentication. This service principal can then be used to limit access to various applications, including PowerShell. Using a service principal is considered best practice for sharing identity with applications and prevents secrets from being stored in code repositories. Commands Used in This Lesson

$sp = New-AzADServicePrincipal -DisplayName myNewSP2

$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sp.Secret)

$UnsecureSecret = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

$UnsecureSecret
Script Used in This Lesson (Used in Windows PowerShell)
$cert = New-SelfSignedCertificate -CertStoreLocation "cert:CurrentUserMy" `
  -Subject "CN=exampleappScriptCert" `
  -KeySpec KeyExchange
$keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData())

$sp = New-AzADServicePrincipal -DisplayName exampleapp `
  -CertValue $keyValue `
  -EndDate $cert.NotAfter `
  -StartDate $cert.NotBefore
Sleep 20
New-AzRoleAssignment -RoleDefinitionName Reader -ServicePrincipalName $sp.ApplicationId

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

01:45:00

Provisioning with PowerShell in Azure

Using RunAs to Background Tasks

00:07:35

Lesson Description:

In this lesson, we go through the method of sending certain tasks into the background. This saves us time in having to wait while a VM is created, for example. We demonstrate this in use and also talk about context and switching between different subscriptions using contexts in Azure. Commands Used in This Lesson

$job = New-AzVM -Name myNewUbuntuVM -AsJob -ImageName UbuntuLTS

Get-Job

Get-AzContext -ListAvailable

Get-AzSubscription -SubscriptionName 'MySubscriptionName' | Set-AzContext -Name 'prod'

Get-AzSubscription -SubscriptionName 'MySubscriptionName' | Set-AzContext -Name 'test'

Get-AzContext -ListAvailable

Set-AzContext -Context $(Get-AzContext -Name "mycontext")

Deployment Modes

00:11:05

Lesson Description:

In this lesson, we talk about complete mode versus incremental mode. We also demonstrate complete mode and how it deletes everything in the resource group, except for what's specified in the ARM template.Deployment ModesCommands Used in This Lesson

$rg = "<RESOURCE_GROUP_NAME>"

New-AzResourceGroupDeployment `
  -Mode Complete `
  -Name DeployStorage `
  -ResourceGroupName $rg `
  -TemplateFile ./storage.json
storage.json ARM Template
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_ZRS",
        "Premium_LRS"
      ],
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {
    "storageAccountName": "[concat('store', uniquestring(resourceGroup().id))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('storageAccountName')]",
      "location": "[parameters('location')]",
      "apiVersion": "2019-04-01",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "kind": "StorageV2",
      "properties": {}
    }
  ],
  "outputs": {
    "storageAccountName": {
      "type": "string",
      "value": "[variables('storageAccountName')]"
    }
  }
}

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

00:45:00

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

01:45:00

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

01:45:00

Conclusion

You Did It! What's Next?

00:00:51

Lesson Description:

Congratulations on finishing the course! If you enjoyed it, please give me a thumbs up! Also, if any lessons stood out to you, like those also! Here's some more great PowerShell content on Linux Academy:Azure PowerShell Essentials PowerShell Core for Linux Admins

Take this course and learn a new skill today.

Transform your learning with our all access plan.

Start 7-Day Free Trial