This post will cover how to run the Virtual Machine Manager (VMM) or VirtualMachineManager module from a windows container.
Again like my previous post for SCCM, VirtualMachineManager is not available from PowershellGalary and requires an install from the GUI. Make sure to install just the VMM Admin Console and Powershell modules from the ISO’s installer on a donor server so we can grab the files needed.
Now the difference with this one is that we don’t need to register any dll’s, we just need to make sure we have all correct folders deployed into the container and have the environment variable path for PSModulePath updated to include the path to the VMM Powershell modules.
Copy all the files in C:\Program Files\Microsoft System Center\Virtual Machine Manager identified above into a folder as we will zip up the contents into a file called SCVMM.zip, ensure to keep the same folder structure from \Microsoft System Center\Virtual Machine Manager\ as we will need to extract these into the container as part of the dockerfile image build process.
So now that you have the files and have the zip ready, add the following lines into the dockerfile.
#Install SCVMM Dependencies COPY SCVMM.zip . RUN powershell "Expand-Archive -Path SCVMM.zip -DestinationPath 'C:\Program Files\'"
Now this time we create a file called UpdatePSPath.ps1 then add the following contents to it
Set-ExecutionPolicy Unrestricted -Scope LocalMachine -force #Update PSModulePath $CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine") [Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";C:\Program Files\Microsoft System Center\Virtual Machine Manager\bin\psModules\", "Machine")
Now we add the lines below to clean up the SCVMM.zip and UpdatePSPath.ps1 files which are no longer needed in the container (save space and keep the image lean and clean)
#Cleanup RUN powershell "Remove-Item SCVMM.zip" RUN powershell "Remove-Item UpdatePSPath.ps1"
So in the end your dockerfile should look something like this
FROM mcr.microsoft.com/windows/servercore:ltsc2022 WORKDIR /azp #Disable UAC RUN powershell "Set-ItemProperty -Path REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -Value 0" #Install SCVMM module into container COPY SCVMM.zip . RUN powershell "Expand-Archive -Path SCVMM.zip -DestinationPath 'C:\Program Files (x86)\'" #Register dependencies for SCVMM in container COPY RegisterDlls.ps1 . RUN powershell .\RegisterDlls.ps1 #Cleanup RUN powershell "Remove-Item SCVMM.zip" RUN powershell "Remove-Item UpdatePSPath.ps1" #Enable UAC RUN powershell "Set-ItemProperty -Path REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -Value 1" #Run the Script on Container Start COPY RunAgent.ps1 . CMD powershell .\RunAgent.ps1
Now just run the docker image build command, sit back and chill!
Hope it was helpful