1

I'm trying to get [poshrunner.exe] to be able to run a script in a PowerShell version 2.0 environment on a machine where PowerShell version 3.0 is installed. PowerShell.exe supports this, although it seems that distinct support for PowerShell 1.0 is dubious.

I'm running Windows 8. I have two versions of System.Management.Automation.dll in my GAC:

  • System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (loaded by powershell.exe -version 3.0)
  • System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (loaded by powershell.exe -version 1.0 and powershell.exe -version 2.0)

As far as I can tell I have no publisher policy assembly for System.Management.Automation.dll

C:\Windows\assembly\GAC_MSIL>dir C:\Windows\assembly\GAC_MSIL\policy*
 Volume in drive C has no label.
 Volume Serial Number is 0207-A8AA

 Directory of C:\Windows\assembly\GAC_MSIL

11/16/2012  11:49 PM    <DIR>          Policy.12.0.Microsoft.Office.Interop.Access.Dao
12/13/2012  11:49 PM    <DIR>          policy.2.1.Microsoft.Web.PlatformInstaller
12/13/2012  11:49 PM    <DIR>          policy.3.0.Microsoft.Web.PlatformInstaller
10/29/2012  03:33 PM    <DIR>          policy.3.5.System.Data.SqlServerCe
10/29/2012  03:33 PM    <DIR>          policy.3.5.System.Data.SqlServerCe.Entity
               0 File(s)              0 bytes
               5 Dir(s)  51,204,710,400 bytes free

C:\Windows\assembly\GAC_MSIL>

However, doing an AppDomain.CurrentDomain.Load("System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); is loading version 3 of the assembly. Assembly.Load() has the same results.

Before calling assembly:

[Before Step Through]

After Calling Assembly:

[After Step Through]

That code happens to be running in a secondary app domain, so I'm willing and able to much about with AppDomain settings. How do I force System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 to laod conditionally at runtime.

Community
  • 1
  • 1
Justin Dearing
  • 14,270
  • 22
  • 88
  • 161

2 Answers2

1

I have had all sorts of issues with System.Management.Automation over time. I recently hit it again and decided to find an alternative way to run PowerShell from .NET using a batch file. See this blog post for code samples: http://www.nootn.com.au/2013/01/run-powershell-from-net-program-without.html

This also mentions how to force it to run a particular version of PowerShell, so if this solution works for you, it may be the answer to your question (assuming you are happy to try and avoid System.Management.Automation).

I hope this helps solve your issue or work around it!

nootn
  • 851
  • 1
  • 12
  • 16
0

If you go to the references in your project, find the reference and tell it to copy to local that should help too.

BRogers
  • 3,534
  • 4
  • 23
  • 32