How can I run PowerShell with the .NET 4 runtime?

前端 未结 11 2188
走了就别回头了
走了就别回头了 2020-11-22 07:38

I am updating a PowerShell script that manages some .NET assemblies. The script was written for assemblies built against .NET 2 (the same version of the framework that Power

11条回答
  •  遇见更好的自我
    2020-11-22 08:01

    The best solution I have found is in the blog post Using Newer Version(s) of .NET with PowerShell. This allows powershell.exe to run with .NET 4 assemblies.

    Simply modify (or create) $pshome\powershell.exe.config so that it contains the following:

     
     
         
             
             
         
     
    

    Additional, quick setup notes:

    Locations and files are somewhat platform dependent; however will give you an inline gist of how to make the solution work for you.

    • You can find PowerShell's location on your computer by executing cd $pshome in the Powershell window (doesn't work from DOS prompt).
      • Path will be something like (example) C:\Windows\System32\WindowsPowerShell\v1.0\
    • The filename to put configuration in is: powershell.exe.config if your PowerShell.exe is being executed (create the config file if need be).
      • If PowerShellISE.Exe is running then you need to create its companion config file as PowerShellISE.Exe.config

提交回复
热议问题