AVD Management Using Visual Studio Code Instead of PowerShell ISE

In this post, let’s learn how to start AVD Management Using Visual Studio Code Instead of PowerShell ISE. Well, Azure Virtual Desktop (AVD) supports only PowerShell core 7.0 or later. I have been extensively using PowerShell ISE (Yes!). But, I still love GUI and I don’t like coding đŸ™‚

Note! – This post mostly applies to the Windows Virtual Desktop spring 2020 release (a.k.a AVD). This Spring 2020 update uses the Azure Resource Manager (ARM) Windows Virtual Desktop objects.

Windows Virtual Desktop cmdlets (Az.DesktopVirtualization) currently only work with PowerShell Core. So, there is PowerShell ISE support! We need to find out some other way to get PowerShell ISE experience.

Now, don’t ask me why do we need PowerShell commands with AVD’s new portal Experience? Well, one example is personal desktop assignments in AVD v2 and this is only possible using PowerShell Core!

Patch My PC
AVD Management Using Visual Studio Code Instead of PowerShell ISE
AVD Management Using Visual Studio Code Instead of PowerShell ISE

If you don’t want to install Visual Studio code to manage AVD, you can use the latest version of PowerShell Core.

PowerShell Core 7 (Preview)
PowerShell Core 7 (Preview) – AVD Management Using Visual Studio Code Instead of PowerShell ISE

Install Visual Studio Code for AVD Management

Now, you will need to install Visual Studio Code for AVD management.

  • Download the Visual Studio Code for Windows 10 from Microsoft (Direct download).
  • Double click on the VSCodeUserSetup-x64-1.46.0.exe to start the installation.
  • Accept the license terms and click on the Next button.
AVD Management Using Visual Studio Code Instead of PowerShell ISE
AVD Management Using Visual Studio Code Instead of PowerShell ISE

Select the installation folder

C:\Users\Anoop C Nair\AppData\Local\Programs\Microsoft VS Code

Adaptiva

Click on the Next button to continue

AVD Management Using Visual Studio Code Instead of PowerShell ISE
AVD Management Using Visual Studio Code Instead of PowerShell ISE

Setup will create a shortcut folder in the start menu folder with the name – Visual Studio Code.

You can have an option to opt-out of creating a start menu folder.

Click on Next to continue

 Install Visual Studio Code for AVD Management
Install Visual Studio Code for AVD Management

Select the additional options in this window. I have added the following options.

Add the “Open with Code” action to the Windows explorer file context menu

Add the “Open with Code” action to the Windows Explorer directory context menu

  • Register Code as an editor for supported file types
  • Add to PATH (requires shell restart)
  • Click on Next to continue
AVD Management Using Visual Studio Code Instead of PowerShell ISE 1
  • Installing the Microsoft Visual Studio Code (User).
  Install Visual Studio Code for AVD Management
Install Visual Studio Code for AVD Management
  • Installation of Microsoft Visual studio code completed.
  • Click on FINISH to launch the visual studio code app.
WVD Management Using Visual Studio Code Instead of PowerShell ISE
AVD Management Using Visual Studio Code Instead of PowerShell ISE

Configure PowerShell in Visual Studio Code for AVD

You will need to configure PowerShell in Visual Studio Code for AVD.

  1. Press Ctrl+P (Quick-Open) to launch the search option
  2. In Quick-Open, type ext install powershell and press Enter.
  3. Select the Powershell Extension for Visual Studio Code (PowerShell Scripts in Visual Studio code).
  4. Click on the Install button to continue.
 Configure PowerShell in Visual Studio Code for AVD
Configure PowerShell in Visual Studio Code for AVD
  • Run the Following Commands from the Terminal.
Install-Module -Name Microsoft.RDInfra.RDPowerShell

Install-Module -Name Az.DesktopVirtualization -RequiredVersion 2.1.0

Import-Module -Name Microsoft.RDInfra.RDPowerShell
Configure PowerShell in Visual Studio Code for AVD
Configure PowerShell in Visual Studio Code for AVD

Run the following commands to select the appropriate subscription.

Connect-AzAccount

Get-AzSubscription | Out-GridView -PassThru | Select-AzSubscription

Update-AzWvdHostPool -ResourceGroupName WVD-Resource-Group -Name HostPool -StartVMOnConnect:$True  
AVD Management Using Visual Studio Code Instead of PowerShell ISE
AVD Management Using Visual Studio Code Instead of PowerShell ISE

Select PowerShell ISE as shown in the below screen capture. (I can’t get this option from the latest version of VS Code?).

WVD Management Using Visual Studio Code Instead of PowerShell ISE
AVD Management Using Visual Studio Code Instead of PowerShell ISE
FunctionISE BindingVS Code Binding
Interrupt and break debuggerCtrl+BF6
Execute current line/highlighted textF8F8
List available snippetsCtrl+JCtrl+Alt+J
ISE Key Binding in VC Code

Results – AVD Management Using Visual Studio Code Instead of PowerShell ISE

I can get a very similar experience as PowerShell ISE using VS code (Visual Studio Code). More details are below:

  • If you already imported the PowerShell modules on Windows 10 device, then you don’t have to import those modules again.
  • You can have the Terminal window on the left side.
  • You can use the existing PS1 files using visual studio code now.
WVD V2 Management Using Visual Studio Code Instead of PowerShell ISE
AVD Management Using Visual Studio Code Instead of PowerShell ISE
  • The following are the sample PowerShell core commands you can try in VS code to manage AVD V2.
>Get-AzWvdSessionHost -HostPoolName $Hostpoolname -ResourceGroupName $ResourcegroupName | Format-List
>Get-AzWvdHostPool -ResourceGroupName $ResourcegroupName | Format-List
WVD V2 Management Using Visual Studio Code Instead of PowerShell ISE
AVD V2 Management Using Visual Studio Code Instead of PowerShell ISE

Resources

Author

Anoop is Microsoft MVP! He is a Solution Architect in enterprise client management with more than 20 years of experience (calculation done in 2021) in IT. He is Blogger, Speaker, and Local User Group HTMD Community leader. His main focus is on Device Management technologies like SCCM 2012, Current Branch, and Intune. He writes about ConfigMgr, Windows 11, Windows 10, Azure AD, Microsoft Intune, Windows 365, AVD, etc……………

4 thoughts on “AVD Management Using Visual Studio Code Instead of PowerShell ISE”

  1. Hi, thanks for your article. Is it possible to use Visual Studio in WVD? Do I use the normal installation package or is there a special one?

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.