During a runbook creation this morning, I needed to utilise the VirtualMachineManager PowerShell module. When trying to import the module I receive the following error:
Import-Module : Could not load file or assembly ‘file:///C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\Microsoft.SystemCenter.VirtualMachineManager.dll’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
After some investigation, I found it was down to a PowerShell configuration setting that needed to allow the use of DotNet 4 assemblies. To get this working, I needed to create a new configuration file into my PowerShell root directory called Powershell.exe.config:
< ?xml version="1.0"? >
< configuration >
< startup useLegacyV2RuntimeActivationPolicy="true" >
< supportedRuntime version="v4.0.30319"/ >
< supportedRuntime version="v2.0.50727"/ >
< /startup >
< /configuration >
**The above script is basically in XML, make sure you remove the spaces after the < and before the >.**
Once added, I was able to import the module within my own session. However, whenever my Runbook was called, it failed with the same error message. It turns out you need to add a couple of registry keys to change the global behaviour for your DotNet Configuration:
reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
As soon as I added the keys, I was able to call the VirtualMachineManager module and access the cmdlets.
This post is my own work and does not have any connection with my employer.
Following any of the information in these posts are at your own risk. TameYourCloud do not accept any responsibility for any issues that may arise.
This content is owned by Paul Sanders from TameYourCloud.com. This cannot be copied or distributed without his express permission. A simple quotation for up to 2 sentances maybe used, but a link to the original post must be provided.