Skip to content

Commit 083d2a8

Browse files
Merge pull request #264184 from dknappettmsft/avd-test-msix-powershell-update
AVD test MSIX package updated PowerShell
2 parents 8417960 + ec75bd2 commit 083d2a8

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

articles/virtual-desktop/app-attach-test-msix-packages.md

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn how to mount disk images for testing and troubleshooting outs
44
ms.topic: how-to
55
author: dknappettmsft
66
ms.author: daknappe
7-
ms.date: 11/27/2023
7+
ms.date: 01/25/2024
88
---
99

1010
# Test MSIX packages for app attach
@@ -46,19 +46,17 @@ Staging and destaging are machine-level operations, while registering and deregi
4646
4747
## Prepare to stage an MSIX package
4848

49-
The staging script prepares your machine to receive the MSIX package and mounts the relevant package to your machine. You only need to run the following commands once per machine.
50-
51-
However, if you're using an image in CimFS format, or a version of PowerShell greater than 5.1, the instructions are different. Later versions of PowerShell are multi-platform, which means the Windows application parts are split off into their own package called [Windows Runtime](/windows/uwp/winrt-components/). You need to use a variation of the commands to install a package with a multi-platform version of PowerShell.
49+
The staging script prepares your machine to receive the MSIX package and mounts the relevant package to your machine.
5250

5351
Select the relevant tab for the version of PowerShell you're using.
5452

5553
# [PowerShell 6 and later](#tab/posh6)
5654

57-
To stage packages at boot using PowerShell 6 or later, you need to run the following commands before the staging operations to bring the capabilities of the Windows Runtime package to PowerShell.
55+
To stage packages using PowerShell 6 or later, you need to run the following commands before the staging operations to bring the capabilities of the Windows Runtime package to PowerShell.
5856

5957
1. Open a PowerShell prompt as an administrator.
6058

61-
1. Run the following command to download and install the Windows Runtime Package:
59+
1. Run the following command to download and install the Windows Runtime Package. You only need to run the following commands once per machine.
6260

6361
```powershell
6462
#Required for PowerShell 6 and later
@@ -73,15 +71,15 @@ To stage packages at boot using PowerShell 6 or later, you need to run the follo
7371
#Required for PowerShell 6 and later
7472
$nuGetPackageName = 'Microsoft.Windows.SDK.NET.Ref'
7573
$winRT = Get-Package $nuGetPackageName
76-
$dllWinRT = Get-Childitem (Split-Path -Parent $winRT.Source) -Recurse -File WinRT.Runtime.dll
77-
$dllSdkNet = Get-Childitem (Split-Path -Parent $winRT.Source) -Recurse -File Microsoft.Windows.SDK.NET.dll
74+
$dllWinRT = Get-ChildItem (Split-Path -Parent $winRT.Source) -Recurse -File WinRT.Runtime.dll
75+
$dllSdkNet = Get-ChildItem (Split-Path -Parent $winRT.Source) -Recurse -File Microsoft.Windows.SDK.NET.dll
7876
Add-Type -AssemblyName $dllWinRT.FullName
7977
Add-Type -AssemblyName $dllSdkNet.FullName
8078
```
8179

8280
# [PowerShell 5.1 and earlier](#tab/posh5)
8381

84-
To stage packages at boot with PowerShell version 5.1 or earlier, you need to run the following command before the staging operations to bring the capabilities of the Windows Runtime package to PowerShell.
82+
To stage packages with PowerShell version 5.1 or earlier, you need to run the following command before the staging operations to bring the capabilities of the Windows Runtime package to PowerShell.
8583

8684
1. Open a PowerShell prompt as an administrator.
8785

@@ -110,9 +108,9 @@ To mount a CimFS disk image:
110108
1. In the same PowerShell session, run the following command:
111109

112110
```powershell
113-
$diskImage = "<UNC path to the Disk Image>"
111+
$diskImage = "<Local or UNC path to the disk image>"
114112
115-
$mount = Mount-CimDiskimage -ImagePath $diskImage -PassThru -NoMountPath
113+
$mount = Mount-CimDiskImage -ImagePath $diskImage -PassThru -NoMountPath
116114
117115
#We can now get the Device Id for the mounted volume, this will be useful for the destage step.
118116
$deviceId = $mount.DeviceId
@@ -130,9 +128,9 @@ To mount a VHDX or VHD disk image:
130128
1. In the same PowerShell session, run the following command:
131129

132130
```powershell
133-
$diskImage = "<UNC path to the Disk Image>"
131+
$diskImage = "<Local or UNC path to the disk image>"
134132
135-
$mount = Mount-Diskimage -ImagePath $diskImage -PassThru -NoDriveLetter -Access ReadOnly
133+
$mount = Mount-DiskImage -ImagePath $diskImage -PassThru -NoDriveLetter -Access ReadOnly
136134
137135
#We can now get the Device Id for the mounted volume, this will be useful for the destage step.
138136
$partition = Get-Partition -DiskNumber $mount.Number
@@ -153,7 +151,7 @@ Finally, you need to run the following commands for all image formats to complet
153151
1. In the same PowerShell session, retrieve the application information by running the following commands:
154152

155153
```powershell
156-
$manifest = Get-Childitem -LiteralPath $deviceId -Recurse -File AppxManifest.xml
154+
$manifest = Get-ChildItem -LiteralPath $deviceId -Recurse -File AppxManifest.xml
157155
$manifestFolder = $manifest.DirectoryName
158156
```
159157

@@ -180,12 +178,18 @@ Finally, you need to run the following commands for all image formats to complet
180178
$packageManager = New-Object -TypeName Windows.Management.Deployment.PackageManager
181179
182180
$asyncOperation = $packageManager.StagePackageAsync($folderAbsoluteUri, $null, "StageInPlace")
183-
$stagingResult = $asTaskAsyncOperation.Invoke($null, @($asyncOperation))
184181
```
185182

186-
1. Check the `$stagingResult` variable to monitor the staging progress for the application package by running the following command:
183+
1. Monitor the staging progress for the application package by running the following commands. The time it takes to stage the package depends on its size. The `Status` property of the `$stagingResult` variable will be `RanToCompletion` when the staging is complete.
187184

188185
```powershell
186+
$stagingResult = $asTaskAsyncOperation.Invoke($null, @($asyncOperation))
187+
188+
while ($stagingResult.Status -eq "WaitingForActivation") {
189+
Write-Output "Waiting for activation..."
190+
Start-Sleep -Seconds 5
191+
}
192+
189193
Write-Output $stagingResult
190194
```
191195

@@ -200,31 +204,30 @@ $manifestPath = Join-Path (Join-Path $Env:ProgramFiles 'WindowsApps') (Join-Path
200204
Add-AppxPackage -Path $manifestPath -DisableDevelopmentMode -Register
201205
```
202206

203-
Now that your MSIX package is registered, your application should be available for use in your session. You can now open the application for testing and troubleshooting. Once you're finished, you can deregister and destage your MSIX package.
207+
Now that your MSIX package is registered, your application should be available for use in your session. You can now open the application for testing and troubleshooting. Once you're finished, you need to deregister and destage your MSIX package.
204208

205209
## Deregister an MSIX package
206210

207-
Once you're finished with your MSIX package and are ready to remove it, you need to deregister it. To deregister an MSIX package, run the following command in the same PowerShell session. This command uses the `$msixPackageFullName` variable created in a previous section.
211+
Once you're finished with your MSIX package and are ready to remove it, first you need to deregister it. To deregister the MSIX package, run the following commands in the same PowerShell session. These commands get the disk's `DeviceId` parameter again, and removes the package using the `$msixPackageFullName` variable created in a previous section.
208212

209213
```powershell
214+
$appPath = Join-Path (Join-Path $Env:ProgramFiles 'WindowsApps') $msixPackageFullName
215+
$folderInfo = Get-Item $appPath
216+
$deviceId = '\\?\' + $folderInfo.Target.Split('\')[0] +'\'
217+
Write-Output $deviceId #Save this for later
218+
210219
Remove-AppxPackage $msixPackageFullName -PreserveRoamableApplicationData
211220
```
212221

213222
## Destage an MSIX package
214223

215-
To destage an MSIX package, run the following commands in the same PowerShell session to get the disk's `DeviceId` parameter. This command uses the `$msixPackageFullName` variable created in a previous section.
224+
Finally, to destage the MSIX package, you need to dismount your disk image, run the following command in the same PowerShell session to ensure that the package isn't still registered for any user. This command uses the `$msixPackageFullName` variable created in a previous section.
216225

217-
```powershell
218-
$appPath = Join-Path (Join-Path $Env:ProgramFiles 'WindowsApps') $msixPackageFullName
219-
$folderInfo = Get-Item $appPath
220-
$deviceId = '\\?\' + $folderInfo.LinkTarget.Split('\')[0] +'\'
221-
Write-Output $deviceId #Save this for later
222-
223-
Remove-AppxPackage -AllUsers -Package $msixPackageFullName
224-
Remove-AppxPackage -Package $msixPackageFullName
226+
```powershell
227+
Remove-AppxPackage -AllUsers -Package $msixPackageFullName -ErrorAction SilentlyContinue
225228
```
226229

227-
### Dismount the disks from the system
230+
### Dismount the disks image
228231

229232
To finish the destaging process, you need to dismount the disks from the system. The command you need to use depends on the format of your disk image. Select the relevant tab for the format you're using.
230233

@@ -233,15 +236,15 @@ To finish the destaging process, you need to dismount the disks from the system.
233236
To dismount a CimFS disk image, run the following commands in the same PowerShell session:
234237

235238
```powershell
236-
DisMount-CimDiskimage -DeviceId $deviceId
239+
Dismount-CimDiskImage -DeviceId $deviceId
237240
```
238241

239242
### [VHDX or VHD](#tab/vhdx)
240243

241244
To dismount a VHDX or VHD disk image, run the following command in the same PowerShell session:
242245

243246
```powershell
244-
DisMount-DiskImage -DevicePath $deviceId.TrimEnd('\')
247+
Dismount-DiskImage -DevicePath $deviceId.TrimEnd('\')
245248
```
246249

247250
---
@@ -250,7 +253,7 @@ Once you finished dismounting your disks, you've safely removed your MSIX packag
250253

251254
## Set up simulation scripts for the MSIX app attach agent
252255

253-
If you want to add and remove MSIX packages to your device automatically, you can use the PowerShell commands in this article to create scripts that run at startup, logon, logoff, and shutdown. To learn more, see [Using startup, shutdown, logon, and logoff scripts in Group Policy](/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/dn789196(v=ws.11)/).
256+
If you want to add and remove MSIX packages to your device automatically, you can use the PowerShell commands in this article to create scripts that run at startup, logon, logoff, and shutdown. To learn more, see [Using startup, shutdown, logon, and logoff scripts in Group Policy](/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/dn789196(v=ws.11)/). You need to make sure that any variables required for each phase are available in each script.
254257

255258
You create a script for each phase:
256259

@@ -304,7 +307,7 @@ Here's how to set up a license for offline use:
304307
}
305308
catch [Exception]
306309
{
307-
Write-Host $_ | out-string
310+
Write-Host $_ | Out-String
308311
}
309312
```
310313

0 commit comments

Comments
 (0)