How do I change SCOM Agent Powershell runtime to .NET 4?
Hello,
I have a powershell cmdlet that I need to use from my discovery script. Powershell by default used the v2 runtime but my code has v4 dependencies that I cannot change. I can load and use the cmdlet in a normal powershell prompt by tweaking the
PowerShellEngine RuntimeVersion value in the registry to v4.0.30319 as per:
http://dougfinke.com/blog/index.php/2010/04/18/how-to-add-an-f-type-to-a-powershell-session/
However, when my agent attempts to load the snap-in I get the error below:
The specified snap-in '[MyDll]' failed to load with below exception
System.Management.Automation.Runspaces.PSSnapInException: Cannot load Windows PowerShell snap-in [MyDll] because of the following error: Could not load file or assembly 'file:///C:\cmdlets\[MyDll]' or one of its dependencies. This assembly is built by
a runtime newer than the currently loaded runtime and cannot be loaded.
at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)
at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo)
at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo, PSSnapInException& warning)
at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.DoAddPSSnapIn(String name, PSSnapInException& warning)
at Microsoft.EnterpriseManagement.Modules.PowerShell.RunspaceConfigurationContainer.GetRunspaceConfiguration()
Is there any way I can change the way in which Operations Manager invokes Powershell?
Thanks in advance,
Scott
November 26th, 2010 12:52pm
Oh, I'm working in a 64 bit environment, loading my cmdlet dll via the Framework64 installutil.exe. The OS is Windows Server 2008 SP2.
Free Windows Admin Tool Kit Click here and download it now
November 26th, 2010 12:53pm
In my total frustration I omitted the fact that I'm working with SCOM 2007 R2! :)
November 26th, 2010 3:34pm
Any ideas anyone?
Free Windows Admin Tool Kit Click here and download it now
December 1st, 2010 4:28am
For the record, the solution to this was to invoke another powershell process from within the script run by the SCOM embedded powershell runtime. The invoked one uses the version of powershell on the path and as such will pick up any alternative
runtime configuration setting and make the .NET 4 libraries accessible. Unfortunately this does lead to writing powershell scripts escaped in strings in powershell scripts themselves embedded in xml management pack files. Lovely.
January 11th, 2011 10:41am