Skip to content

Commit 8bf103f

Browse files
Support DISM in host initialization with MSIX PowerShell (#98)
## Summary - Import the DISM module through Windows PowerShell compatibility when `host_init.ps1` runs in MSIX-packaged PowerShell 7, retaining native DISM calls for unpackaged installs. - Stop on DISM query or installation errors instead of continuing with setup after a failed feature check. - Document the workaround and the separate PowerShell 7 remoting limitation of MSIX for the rest of the lab. Workaround for PowerShell/PowerShell#13866. ## Validation - PowerShell syntax parsed successfully, and the compatibility import exposed all four DISM commands as proxy functions locally. - User reports running the updated script on their machine; the host's feature state was not independently verified in this worktree. Co-authored-by: Copilot App <[email protected]>
1 parent 1735671 commit 8bf103f

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Run the host_init.ps1 script to initialize the host environment:
7474
.\host_init.ps1
7575
```
7676

77+
For MSIX installations of PowerShell 7, the script runs DISM commands through Windows PowerShell 5.1 compatibility. The rest of the lab requires a PowerShell 7 remoting endpoint, which MSIX installations do not support.
78+
7779
You may need to reboot the host for the Hyper-V feature installation to complete.
7880

7981
## Golden Image

‎powershell/host_init.ps1‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ function Invoke-HostInit {
55
param(
66
)
77

8+
if ($PSHOME -like "${Env:ProgramFiles}\WindowsApps\*") {
9+
Import-Module Dism -UseWindowsPowerShell -ErrorAction Stop
10+
}
11+
812
$IsChocoPresent = [bool](Get-Command -Name choco -CommandType Application -ErrorAction SilentlyContinue)
913
$IsWingetPresent = [bool](Get-Command -Name winget -CommandType Application -ErrorAction SilentlyContinue)
1014

@@ -34,8 +38,8 @@ function Invoke-HostInit {
3438
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\Credssp" `
3539
-Name UseCachedCRLOnlyAndIgnoreRevocationUnknownErrors -Value 1 -Force | Out-Null
3640

37-
if ($(Get-WindowsCapability -Online -Name "OpenSSH.Client~~~~0.0.1.0").State -ne "Installed") {
38-
Add-WindowsCapability -Online -Name "OpenSSH.Client~~~~0.0.1.0"
41+
if ($(Get-WindowsCapability -Online -Name "OpenSSH.Client~~~~0.0.1.0" -ErrorAction Stop).State -ne "Installed") {
42+
Add-WindowsCapability -Online -Name "OpenSSH.Client~~~~0.0.1.0" -ErrorAction Stop
3943
}
4044

4145
if (-Not (Get-InstalledModule PsHosts -ErrorAction SilentlyContinue)) {
@@ -85,8 +89,8 @@ function Invoke-HostInit {
8589
}
8690

8791
# Enable Hyper-V (requires a reboot)
88-
if ($(Get-WindowsOptionalFeature -Online -FeatureName "Microsoft-Hyper-V").State -ne 'Enabled') {
89-
Enable-WindowsOptionalFeature -Online -FeatureName @("Microsoft-Hyper-V") -All -NoRestart
92+
if ($(Get-WindowsOptionalFeature -Online -FeatureName "Microsoft-Hyper-V" -ErrorAction Stop).State -ne 'Enabled') {
93+
Enable-WindowsOptionalFeature -Online -FeatureName @("Microsoft-Hyper-V") -All -NoRestart -ErrorAction Stop
9094
}
9195

9296
# Create LAN switch for the host and VMs

0 commit comments

Comments
 (0)