Uncategorized

Using PowerShell with WVD Part 1

Hi everyone, this post in a series of posts which I am looking to write around different methods of interacting with Windows Virtual Desktop via different methods. I am hoping to explore PowerShell, JSON, Terraform, Ansible, GitHub, DevOps, Pipelines etc.

We will create host pools, build images, use Image Builder and a whole load of other stuff also! I may post a few times a week, everyday, or once a week, whenever time allows!

I hope you will enjoy the series as we get to learn about all the above technologies, Azure & WVD!! So let’s get started with some PowerShell basics as a kick off.

Requirements

To query WVD via PowerShell we need to install the Azure PowerShell AZ Module. The recommended version of PowerShell for use of Azure PowerShell is PowerShell 7.x so that is the version that we shall use. To get the version of PowerShell that you use, you can use the PowerShell command:

Get-Host | Select-object version

As you can see we are running PowerShell 5.1 and ideally we want to be on 7.x. So if you head over to https://github.com/PowerShell/PowerShell you can grab the latest available version and install it. I won’t go through the installations steps but at the end you should have PowerShell 7.x installed. I have v7.0.3. To get the version I used a separate command:

$PSVersionTable.PSVersion

Installing the Azure PowerShell Module

Now that we have the latest version of PowerShell up and running we can install the Azure PowerShell module. To do this use the following command:

if ($PSVersionTable.PSEdition -eq ‘Desktop’ -and (Get-Module -Name AzureRM -ListAvailable)) {
Write-Warning -Message (‘Az module not installed. Having both the AzureRM and ‘ +
‘Az modules installed at the same time is not supported.’)
} else {
Install-Module -Name Az -AllowClobber -Scope CurrentUser
}

For the original code visit here – https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-4.5.0

You should now see the installation run successfully

Now we should be able to use the WVD AZ Cmdlets. In this example I ran Get-AZWVDHostPool which complained about me not being connected to a subscription which we will cover next

Connecting to your WVD Environment

OK so now we have the correct version of PowerShell installed and we have the correct cmdlets installed, we can now try and query our WVD resources. To do this we use the Connect-AZAccount command.

This then asks us to authenticate to Azure and enter a code

After successfully authenticating we should see our subscription

We now should be able to query our environment using the built in commands.

So that’s it for this post. In this post we covered the installing PowerShell 7, installing the Azure PowerShell module and connecting to our Azure subscription and querying WVD.

In our next post we will go into a bit more depth about what we can cover and perform some basic tasks!

Till next time 🙂

Leave a Reply

Your email address will not be published.