简体   繁体   中英

How do I force a load of System.Management.Automation.dll v1.0 from a machine that has PowerShell version 3.0 on it?

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:

[ 逐步执行之前 ]

After Calling Assembly:

[ 逐步完成之后 ]

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.

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!

如果您转到项目中的参考,请找到参考并将其复制到本地,这也应该有所帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM