Skip to content

Instantly share code, notes, and snippets.

@jborean93
Created November 10, 2024 21:40
Show Gist options
  • Save jborean93/f6f2794bbe25628f6b39003e28f5f660 to your computer and use it in GitHub Desktop.
Save jborean93/f6f2794bbe25628f6b39003e28f5f660 to your computer and use it in GitHub Desktop.
Fix Appx in PSRemoting for Server 2025
# Server 2025 fails to run Get-AppxPackage and other DISM module commands in
# a PSRemoting (psrp) session as it has a dependency on some dll's not present
# in the GAC and only in the powershell.exe directory. As PSRP runs through
# wsmprovhost.exe, it fails to find those dlls. This hack will manually load
# the 4 required dlls into the GAC. This is a hack and should be removed in the
# future if MS fix their bug on 2025.
Add-Type -AssemblyName "System.EnterpriseServices"
$publish = [System.EnterpriseServices.Internal.Publish]::new()
@(
'System.Numerics.Vectors.dll',
'System.Runtime.CompilerServices.Unsafe.dll',
'System.Security.Principal.Windows.dll',
'System.Memory.dll'
) | ForEach-Object {
$dllPath = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\$_"
$publish.GacInstall($dllPath)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment