Skip to main content

Azure PowerShell Essentials

Course

Intro Video

Photo of Corey Knapp

Corey Knapp

Azure Training Architect II

Corey has been in the IT Industry for over 21 years, specializing in Microsoft Infrastructure and Azure IaaS solutions. Born in California, raised in New Jersey, and now living in Chapel Hill, North Carolina, Corey has been all over the United States. He loves the winter but hates the cold, and loves the summer but hates the heat. Even in his own mind, Corey is an enigma. In his free time, he loves spending time with his teenage children and his wife of 18 years, Michele. Corey has a passion for learning and is ready to spread that eagerness to others.

Length

04:18:57

Difficulty

Beginner

Videos

32

Hands-on Labs

5

Course Details

This beginner-level course teaches the essentials of using PowerShell, PowerShell Core, and the Azure PowerShell module to manage your Azure environment using the command line.

You will learn basic concepts and syntax of PowerShell to create and manage resources, subscriptions, and identities in Azure, and also gain a basic understanding of how to build your own scripts.

These essential skills will help you use PowerShell to automate your administrative tasks, as well as gather useful information from your Azure resources.

Syllabus

Course Introduction

Welcome to the Course

Course Introduction

00:01:14

Lesson Description:

Welcome to this course on Azure PowerShell where we will become confident and competent with the following:The syntax, structure, and usage of PowerShell and Azure PowerShell. Managing Azure resources through Azure PowerShell. Building scripts in PowerShell ISE and Visual Studio Code that use Azure PowerShell.This lesson provides a walkthrough of the objectives of the course and the types of topics we will discuss. To follow along with this course, either use a local installation of Azure PowerShell or use PowerShell built into the Cloud Shell within the Azure Portal. In order to perform the creation and management tasks covered in this course, either use your own Azure subscription or utilize the hands-on labs.

About the Training Architect

00:00:21

Lesson Description:

Greetings! Welcome to this Linux Academy course! My name is Corey Knapp, and I'll be the training architect for this course on Azure PowerShell. I'm excited to help on this journey from PowerShell Zero to PowerShell Hero! I'd love you hear from you. Please feel free to reach out to me in commnunity or in the Linux Academy Community Slack channel.

Introduction to PowerShell

PowerShell Basics

What is PowerShell?

00:02:54

Lesson Description:

In this video, we look at gaining a greater understanding of the following items:What PowerShell is. How it works with Microsoft Azure (Azure Resource Manager API). The four main tools for working with Microsoft Azure. What PowerShell can be used for.

Installing PowerShell

00:03:07

Lesson Description:

In this lesson, we learn where PowerShell is installed by default and how to install PowerShell Core from the Microsoft GitHub page. PowerShell can be found by clicking on the Windows button at the bottom-right of the screen and typing in "PowerShell". The .msi installer for PowerShell Core can be found at https://github.com/PowerShell/PowerShell/releases/tag/v6.2.2. Using PowerShell Core in the Azure Portal requires the creation of a cloud storage account.

PowerShell Versus PowerShell Core

00:07:40

Lesson Description:

In this lesson, we discuss the differences between PowerShell and PowerShell Core, including available cmdlets and modules. We also discuss the future of PowerShell Core. Use these commands to follow along with the demonstration:

$PSVersionTable.PSVersion
To obtain a count of the number of commands available:
$M = Get-Command * | Measure
$M.Count
To obtain a count of the number of available modules:
$M = Get-Module -ListAvailable | Measure
$M.Count

Benefits of Learning PowerShell

00:03:34

Lesson Description:

In this lesson, we take a look at some of the benefits of learning Microsoft PowerShell, including administration, automation, and scalability.

Basic Commands in PowerShell

00:12:14

Lesson Description:

This lesson introduces the basic commands everyone should be familiar with when using PowerShell and PowerShell Core. This is not intended to be an in-depth review of these commands, only a basic review of how they are used. A deep dive on these cmdlets will take place later in this course. The following cmdlets are used in this lesson. They can be used to follow along with the demonstration.

Start-Process -Name "notepad"

Stop-Process -Name "notepad"

Get-Help Format-Table

Get-Command -Module Microsoft.PowerShell.Management

Get-Item .

Get-Item *

Get-Content -Path .demo.txt -TotalCount 8

Start-Service -Name "eventlog"

Stop-Service -Name AudioSrv

Get-Service -Name AudioSrv

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Get-ExecutionPolicy -List

Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope Process

Copy-Item "C:UsersDirNamedemo.txt" -Destination "C:Demo"

Remove-Item C:UsersDirName*.*

PowerShell Modules

00:06:52

Lesson Description:

This lesson focuses on how to install and use PowerShell modules. A module is a package that contains PowerShell commands, such as cmdlets, providers, functions, workflows, variables, and aliases. PowerShell users who write commands can use modules to organize their commands and share them with others. PowerShell users who receive modules can add commands in the modules to their PowerShell sessions and use them just like the built-in commands. Module components include code files, assemblies, manifest files, and directories. The four types of PowerShell modules include script modules, binary modules, manifest modules, and dynamic modules. The following commands can be used to follow along with the PowerShell lesson: How to find modules available for installation:

Get-Module -ListAvailable
How to find installed modules:
Get-Module
How to find all commands contained within a module:
Get-Command -Module (module name)
How to get help on commands contained within a module:
Get-Help (command name)
Update and install help files for commands:
Update-Help

PowerShell Concepts

Command and Syntax Basics

00:03:58

Lesson Description:

This lesson covers the basic syntax of PowerShell including the verb-noun structure and parameters. The verb-noun structure in PowerShell enables users to easily understand what the commands will do. For the most part, parameters are just as easy to understand. Common parameters include -help, -confirm, and -verbose. Some of the cmdlets demonstrated in this lesson include the following:Get-Command Get-Service Start-Service Stop-Service

The Three Most Important Commands in PowerShell

00:05:44

Lesson Description:

The three commands covered in this lesson are the building blocks for learning to use PowerShell as a Power User. These commands include:Get-Help Get-Command Get-ServiceWith these three commands, we can pull up documentation on how every cmdlet or function works in PowerShell, get information on specific computers or resources in our operating system or Azure environment, and take a look at the currently running services. Mastering the use of these three commands puts one well on the way to becoming an advanced PowerShell user.

Using Variables

00:02:32

Lesson Description:

Whether we need variables depends on what we're doing in PowerShell. Depending on the user, variables can be an essential means of managing data, a minor and temporary convenience, or they might as well not exist. Ultimately, variables are a tool. We can use them when we find a use for them or leave them alone and take comfort knowing they're managed by our OS. Knowledge is power, and understanding how variables work in PowerShell can lead us to all kinds of unexpected creative problem-solving.

Understanding PowerShell Pipelines

00:02:48

Lesson Description:

Pipelines act like a series of connected segments of pipe. Items moving along the pipeline pass through each segment. To create a pipeline in PowerShell, we connect commands together with the pipe operator: |. The output of each command is used as input to the next command. PowerShell cmdlets are designed to utilize the power of pipelines. For example, we can usually pipe the results of a Get cmdlet to an action cmdlet (e.g. a Set, Start, Stop, or Rename cmdlet). This command pipeline starts the WMI service on the computer:

get-service wmi | start-service
Utility cmdlets, such as Get-Member, Where-Object, Sort-Object, Group-Object, and Measure-Object are used almost exclusively in pipelines. We can pipe any objects to these cmdlets. For example, we can pipe all of the processes on the computer to the Sort-Object command and have them sorted by the number of handles in the process.
get-process | sort-object -property handles
Objects can also be piped to the formatting cmdlets (e.g. Format-List and Format-Table), the Export cmdlets (e.g. Export-CSV), and the Out cmdlets (e.g. Out-Printer). We can pipe the Winlogon process to the Format-List cmdlet to display all of the properties of the process in a list.
get-process winlogon | format-list -property *
Mastering pipelines requires practice, but combining simple commands into pipelines saves time and typing as well as makes our scripting more efficient.

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:15:00

PowerShell in Azure

Installing the Azure PowerShell Module

00:02:48

Lesson Description:

In this lesson, we learn how to install the Azure PowerShell module via PowerShell and in offline mode. We do this by installing the Azure PowerShell MSI. Use these commands to follow along with the demonstration. To install the Azure PowerShell module for the current user:

Install-Module -Name Az -AllowClobber -Scope CurrentUser
To install the Azure PowerShell module for all users:
Install-Module -Name Az -AllowClobber -Scope AllUsers
Download the x64 MSI at the link below to install the Azure PowerShell module in offline mode. https://github.com/Azure/azure-powershell/releases/tag/v2.8.0-October2019

Signing into Azure

00:01:28

Lesson Description:

In this lesson, we learn how to sign into Azure using PowerShell. There are three authentication methods: Logging in from the Cloud Shell (automatic).Logging in from a local PowerShell session using Connect-AzAccount and web authentication.Logging in with a service principal.

The Most Important Azure PowerShell Commands

00:05:15

Lesson Description:

In this lesson, we cover some of the most important and commonly-used Azure PowerShell cmdlets. Using these cmdlets, we can list our Azure resources, virtual machines, Storage accounts, and virtual networks. We can also review the information on these resources, start and stop the resources, and change the login credentials we use to access said resources. The cmdlets covered in this lesson include: Get-AzVm and New-AzVmGet-AzSubscriptionStart-AzVm, Stop-AzVm, and Remove-AzVmGet-AzResourcce and Move-AzResourceGet-AzResourceGroup, New-AzResourceGroup, and Set-AzResourceGroupGet-AzStorageAccount and New-AzStorageAccountLogin-AzAccount and Logout-AzAccountGet-AZVirtualNetworkGet-AZLoadBalancerNew-AZVirtualNetworkNew-AzPublicIPAddress

Working with Outputs

00:04:00

Lesson Description:

In this lesson, we learn how to work with PowerShell outputs, specifically their formatting and how to display specific properties. The cmdlets we use to accomplish this are Format-Table, Format-List, and Format-Wide. Use these commands to follow along with the demonstration:

Get-Service -Name win*
Get-Service -Name win* | Format-List
Get-Service -Name win* | Format-List -Property DisplayName,Status,ServiceType
Get-Service -Name win* | Format-List -Property *
Get-Command -Verb Format | Format-Wide
Get-Command -Verb Format | Format-Wide -Property Noun
Get-Command -Verb Format | Format-Wide -Property Noun -Column 3

Using Nested Properties

00:03:16

Lesson Description:

In this lesson, we discuss nested properties in PowerShell and how to access them using Get-Member and the -Property parameter. Since objects can contain collections of objects, it’s important to understand how to inspect object properties from the PowerShell console. While a developer might be quite comfortable with objects-within-objects, DevOps folks, administrators, and cloud architects (i.e. the target audience for PowerShell) might not be. Introducing one of the most useful cmdlets in PowerShell: Get-Member! Use these commands to follow along with the demonstration:

Get-Service
Get-Service -Name WinRM | Format-List
Get-Service -Name WinRM | Get-Member
Get-Service -Name WinRM | Format-List -Property *

Filtering Results

00:03:57

Lesson Description:

This lesson focuses on filtering and selecting PowerShell objects using the Where-Object and Select-Object commands. Using these commands allows us to precisely define what items are displayed or acted on. In addition to the Where-Object and Select-Object cmdlets, we discuss using the $_ operator and comparison operators. Use the commands listed below to follow along with the demonstration:

Get-Service | Where-Object {$_.Status -eq "Running"}
Get-Service | Where-Object {$_.Status -eq "Stopped"}
Get-Service | Where-Object {$_.Status -eq "Stopped"} | Select-Object -First 5
Get-Service | Where-Object {$_.Status -eq "Stopped"} | Select-Object -Last 5

Managing Azure with PowerShell

Managing Azure Resources with PowerShell

Creating Virtual Machines Using PowerShell in Azure

00:05:28

Lesson Description:

Virtual machines are one of the most commonly-used resources in Microsoft Azure. In this lesson, we delve into how to create a resource group, create a virtual machine, launch Remote Desktop from the PowerShell command line, and install IIS onto a created virtual machine. To follow along with the demonstration, use the following commands. To create a resource group:

New-AzResourceGroup -Name myResourceGroup -Location EastUS
To create the virtual machine:
New-AzVm `
    -ResourceGroupName "myResourceGroup" `
    -Name "myVM" `
    -Location "East US" `
    -VirtualNetworkName "myVnet" `
    -SubnetName "mySubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -PublicIpAddressName "myPublicIpAddress" `
    -OpenPorts 80,3389
To obtain the public IP address of your newly created VM:
Get-AzPublicIpAddress -ResourceGroupName "myResourceGroup" | Select "IpAddress"
To launch Remote Desktop from PowerShell:
mstsc /v:publicIpAddress
To install IIS on Windows Server from PowerShell:
Install-WindowsFeature -name Web-Server -IncludeManagementTools

Creating Storage Accounts in Azure

00:02:11

Lesson Description:

In this lesson, we show how to create Azure Storage accounts using PowerShell. We input variables for the resource group and input the commands to create the Standard LRS storage account. Use the following commands to follow along with the demonstration.

`Connect-AzAccount`

`$resourcegroup = "teststorage"`

`New-AzResourceGroup -Name $resourcegroup -Location eastus`

`New-AzStorageAccount -ResourceGroupName $resourcegroup -Name <the name for the storage> -Location eastus -SkuName Standard_LRS -Kind StorageV2`

Creating Azure SQL Databases

00:08:10

Lesson Description:

In this lesson, we create an Azure virtual machine, install SQL, and create a database using PowerShell. There will be extensive use of variables for resource groups, locations, and names of other resources. To follow along with the demonstration in this lesson, use the following commands. Set variables for your server and database:

$subscriptionID = '<SunscriptionID>'
$resourceGroupName = "DBResourceGrp-$(Get-Random)"
$location = "East US"
$adminLogin = "azureuser"
$password = "Password123!"
$serverName = "mysqlserver-$(Get-Random)"
$databaseName = "mySampleDatabase"
Grant access to the server to an IP address range (leaving at 0.0.0.0 prevents outide-of-Azure connections):
$startIp = "0.0.0.0"
$endIp = "0.0.0.0"
Connect to Azure:
Connect-AzAccount
Set the subscription ID:
Set-AzContext -SubscriptionId $subscriptionId
Create a resource group:
$resourceGroup = New-AzResourceGroup -Name $resourceGroupName -Location $location 
Create a server with a system-wide unique name:
New-AzSqlServer -ResourceGroupName 	$resourceGroupName `
	-ServerName $servername `
	-Location $location `
	-SQLAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential `
	-ArgumentList $adminLogin, $(ConvertTo-SecureString -String $password -AsPlainText -Force))
Create a server firewall rule that allows access from the specified range:
NewAzSQLServerFirewallRule -ResourceGroupName $resourceGroupName `
	-ServerName $serverName `
	-FirewallRuleName "Allowed IPs" -StartIpAddress	$startIp -EndIpAddress $endIp
Create a general purpose Gen5 database with two vCores:
New-AzSqlDatabase -ResourceGroupName $resourceGroupName `
	-ServerName $serverName
	-DatabaseName $databaseName `
	-Edition GeneralPurpose `
	-VCore 2 `
	-ComputeGeneration Gen5 `
	-MinimumCapacity 2 `
	-SampleName "AdventureWorksLT"

Creating Standard Load Balancers in Azure

00:08:50

Lesson Description:

In this lesson, we demonstrate how to create an Azure Standard Load Balancer using PowerShell. To follow along in Cloud Shell on your Azure tenant, use the script below. Create a resource group:

$rgName='MyResourceGroupSLB'
$location='eastus'
New-AzResourceGroup -Name $rgName -Location $location
Create a public IP address:
$publicIp = New-AzPublicIpAddress 
    -ResourceGroupName $rgName 
    -Name 'myPublicIP' 
    -Location $location 
    -AllocationMethod static 
    -SKU Standard
Create the front-end IP:
$feip = New-AzLoadBalancerFrontendIpConfig -Name 'myFrontEndPool' -PublicIpAddress $publicIp
Configure the back-end address pool:
$bepool = New-AzLoadBalancerBackendAddressPoolConfig -Name 'myBackEndPool'
Create a health probe:
$probe = New-AzLoadBalancerProbeConfig 
    -Name 'myHealthProbe' 
    -Protocol Http 
    -Port 80 
    -RequestPath / 
    -IntervalInSeconds 360 
    -ProbeCount 5
Create a Load Balancer rule:
$rule = New-AzLoadBalancerRuleConfig 
    -Name 'myLoadBalancerRuleWeb' 
    -Protocol Tcp 
    -Probe $probe 
    -FrontendPort 80 
    -BackendPort 80 
    -FrontendIpConfiguration $feip 
    -BackendAddressPool $bePool
Create the NAT rules
$natrule1 = New-AzLoadBalancerInboundNatRuleConfig -Name 'myLoadBalancerRDP1' 
    -FrontendIpConfiguration $feip 
    -Protocol tcp -FrontendPort 4221 
    -BackendPort 3389 $natrule2 = New-AzLoadBalancerInboundNatRuleConfig 
    -Name 'myLoadBalancerRDP2'
    -FrontendIpConfiguration $feip 
    -Protocol tcp
    -FrontendPort 4222 
    -BackendPort 3389 $natrule3 = New-AzLoadBalancerInboundNatRuleConfig
    -Name 'myLoadBalancerRDP3' 
    -FrontendIpConfiguration $feip
    -Protocol tcp 
    -FrontendPort 4223
    -BackendPort 3389
Create the Standard Load Balancer
New-AzLoadBalancer -ResourceGroupName $rgName
    -Name 'MyLoadBalancer' 
    -SKU Standard
    -Location $location
    -FrontendIpConfiguration $feip
    -BackendAddressPool $bepool
    -Probe $probe
    -LoadBalancingRule $rule
    -InboundNatRule $natrule1,$natrule2,$natrule3

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:30: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:15: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:30: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:30:00

Managing Azure Identities with PowerShell

Managing Azure Subscriptions

00:01:58

Lesson Description:

The top level of our hierarchy is our organizational level. Microsoft classifies the organization as everything in our domain name. Whatever our domain name is will be the encapsulating component. This organization contains all our subscriptions, which leads to our discussion for this lesson. Everything runs on subscriptions. When we look at our organization and how it's structured, remember an organization grouping can contain multiple subscriptions. The subscription level is where the building and administration components happen. Each subscription can isolate out what we want to do, including development, production, or test platforms. This is also where our billing happens. Learning to set or change our active subscription via PowerShell is essential for our daily administration tasks. To get a list of our current Azure subscriptions, enter the following cmdlet:

Get-AzSubscription
To change our active Azure Subscription, enter the following cmdlet:
Set-AzContext -SubscriptionId &lt;ID Number&gt;

Creating Service Principals

00:02:43

Lesson Description:

This lesson demonstrates the procedure for creating Azure Service Principals via PowerShell, including creating the service principal using the New-AzADServicePrincipal cmdlet. We also showcase creating the credentials for the service principal and assigning them using a variable. To follow along with the demonstration in an Azure tenant, use the following instructions:

$credentials = New-Object Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential -Property @{StartDate=Get-Date; EndDate=Get-Date -Year 2024; Password='Password123!'}
New-AzADServicePrincipal -Displayname LACKTest -PasswordCredential $credentials
(Get-AzContext).Tenant.ID

Creating Users and Groups in Azure

00:04:11

Lesson Description:

In this lesson, we learn how to create users and groups in Azure Active Directory using PowerShell. We go into detail on creating Password Profile Objects for use when creating new Azure AD users, as well as examples of using the New-AzureADUser, New-AzureADGroup, and Add-AzureADGroupMember cmdlets. To follow along with the demonstration, use the following commands:

$passwordprofile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile

$passwordprofile.Password = 'Password123!'

New-AzureADUser -DisplayName "New User" -PasswordProfile $passwordprofile -UserPrincipalName "NewUser@" -AccountEnabled $true -MailNickName "NewUser"

New-AzureADGroup -DisplayName "New Group" -MailEnabled $false -SecurityEnabled $true -MailNickName "NotSet"

Add-AzureADGroupMember -ObjectId "" -RefObjectId ""

Remote Administration

00:06:19

Lesson Description:

In this lesson, we learn how to use PowerShell for remote administration of virtual machines in Azure. We use the Enable-AzVMPSRemoting, Disable-AzVMPSRemoting, Enter-AzVM, and Invoke-AzVMCommand cmdlets. To follow along with the demonstration, use the following commands:


#Cmdlet for getting VM ready for Remote Administration
Enable-AzVMPSRemoting -Name 'VM Name' -ResourceGroupName 'RG Name' -Protocol https -OsType Windows
#Cmdlet which runs the Get-Service cmdlet on the remote VM
Invoke-AzVMCommand -Name 'VM Name' -ResourceGroupName 'RG Name' -ScriptBlock {get-service win*} -Credential (get-credential)
#Cmdlet that open a remote session with the designated VM
Enter-AzVM -name 'VM Name' -ResourceGroupName 'RG Name' -Credential (get-credential)
$hostname
Get-Service win*
Exit
#Cmdlet that disables the configuration for remote administration of the VM
Disable-AzVMPSRemoting -Name 'VM Name' -ResourceGroupName 'RG Name'

Scripting for Azure

Scripting with Azure PowerShell

Using PowerShell ISE

00:07:29

Lesson Description:

In this lesson, we dive into the PowerShell Integrated Scripting Environment (ISE). We learn some of the key features of PowerShell ISE and start looking into how we can create scripts, run pieces of the script, and run the entire script once we've finished editing it. To follow along with the demonstration, I've included a copy of sample code here:


#variables for common values
$resourcegroup = "myResourceGroup"
$location = "westeurope"
$vmName = "myVM"

#Create user object
$cred = Get-Credential -Message "Enter a username and password for the virtual machine."

#Create a resource group
New-AzResourceGroup -Name $resourcegroup -Location $location

#Create a virtual machine
New Az-VM `
    -ResourceGroupName $resourcegroup `
    -Name $vmName `
    -Location $location `
    -ImageName "win2016Datacenter" `
    -VirtualNetworkName "myVNet" `
    -SubnetName "mySubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -PublicIpAddressName "myPublicIp" `
    -Credential $cred `
    -OpenPorts 3389
    
 

Using Visual Studio Code

00:06:12

Lesson Description:

In this lesson, we look at how to install Visual Studio Code and the PowerShell extension for it. We discuss the differences between PowerShell ISE and Visual Studio Code and look at some of the benefits of using Visual Studio Code over PowerShell ISE. To download Visual Studio Code, click the following link and choose the appropriate installation. https://code.visualstudio.com/download To install the PowerShell extension after Visual Studio Code is installed, press Ctrl+Shift+X to bring up the Extensions page. Type in "PowerShell" and click Install. To follow along with the demonstration, I've included a copy of sample code here:


#variables for common values
$resourcegroup = "myResourceGroup"
$location = "westeurope"
$vmName = "myVM"

#Create user object
$cred = Get-Credential -Message "Enter a username and password for the virtual machine."

#Create a resource group
New-AzResourceGroup -Name $resourcegroup -Location $location

#Create a virtual machine
New Az-VM `
    -ResourceGroupName $resourcegroup `
    -Name $vmName `
    -Location $location `
    -ImageName "win2016Datacenter" `
    -VirtualNetworkName "myVNet" `
    -SubnetName "mySubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -PublicIpAddressName "myPublicIp" `
    -Credential $cred `
    -OpenPorts 3389
    
 

Building a Basic PowerShell Script

00:02:52

Lesson Description:

We've learned about basic PowerShell syntax, some simple Azure PowerShell cmdlets, and how to use both PowerShell ISE and Visual Studio Code. Now it's time to put it all together and build our first PowerShell script. Scripts don't need to be hundreds of lines. The best scripts start small and become larger as the requirements expand and the coder's skills increase. To follow along with this demonstration, open an instance of either PowerShell ISE or Visual Studio Code and type the following:




#Welcome to the Script
Write-Host "Welcome from Linux Academy"


* Save the file as `first.ps1`.
* Run the script from the directory by typing the following.

.first.ps1

* If an `ExecutionPolicy Error` occurs, type in the following command and press `Y` for yes. Then rerun the script.

Set-ExecutionPolicy RemoteSigned

.first.ps1

Inputs and Variables

00:03:24

Lesson Description:

This next lesson builds upon the previous lesson where we created our first PowerShell script. In this demonstration, we build variables for the date, our name, and also add a variable to display the output of Get-AzResource. To follow along with the demo, use the script below in a PowerShell instance or Visual Studio Code.

# Welcome to the script

Write-Host "Welcome from Linux Academy!!!"

# Get the date

$date = Get-Date
Write-Host "Today is " $date

# Get my name

$name = "Corey Knapp"
Write-Host "My name is " $name

# Get all Azure Resources

$Resource = Get-AzResource | Format-Table
$Resource

Exporting Outputs to Usable Formats

00:03:21

Lesson Description:

This final lesson on scripting introduces the concept of exporting outputs into usable formats such as CSV and HTML using the Export-CSV and ConvertTo-HTML cmdlets. To follow along with the demonstration in an instance of PowerShell ISE or Visual Studio Code, use the following script.

# Welcome to the script

Write-Host "Welcome from Linux Academy!!!"

# Get the date

$date = Get-Date
Write-Host "Today is " $date

# Get my name

$name = "Corey Knapp"
Write-Host "My name is " $name

# Get all Azure Resources

Get-AzResource | Export-CSV -Path C:Scriptstest.csv

Get-AzResource | ConvertTo-Html | Out-File C:Scriptstest.html

Next Steps

What's Next?

00:01:55

Lesson Description:

Congratulations on finishing this Azure PowerShell Essentials course! In this video, we do a quick recap of what we've learned and discuss where to go from here. Feel free to reach out with any questions on the Linux Academy forums (@corey.knapp78), community Slack (@Corey Knapp), Twitter (CoreyKnapp12), or on LinkedIn (CoreyKnapp)!

Take this course and learn a new skill today.

Transform your learning with our all access plan.

Start 7-Day Free Trial