locked
How to call a specific version of PowerShell from C#? RRS feed

Tutte le risposte

  • powershell -version 2

    Name                           Value
    ----                           -----
    CLRVersion                     2.0.50727.5466
    BuildVersion                   6.1.7601.17514
    PSVersion                      2.0
    WSManStackVersion              2.0
    PSCompatibleVersions           {1.0, 2.0}
    SerializationVersion           1.1.0.1
    PSRemotingProtocolVersion      2.1

    powershell -version 3

    Name                           Value
    ----                           -----
    WSManStackVersion              3.0
    PSCompatibleVersions           {1.0, 2.0, 3.0}
    SerializationVersion           1.1.0.1
    BuildVersion                   6.2.9200.16481
    PSVersion                      3.0
    CLRVersion                     4.0.30319.296
    PSRemotingProtocolVersion      2.2

    martedì 23 aprile 2013 13:43
  • I know how to do it from command line.  How to call a specific version of PowerShell from C#? I have to do it programmatically.

    Dmitry

    Twitter Lightning Tools LogoLightning Tools Check out our SharePoint tools and web parts | Lightning Tools Blog | Мой Блог

    martedì 23 aprile 2013 18:04
  • Hi,

    Hope the below similar thread could be helpful:

    call-a-specific-version-of-powershell-from-c-sharp

    http://stackoverflow.com/questions/16148305/call-a-specific-version-of-powershell-from-c-sharp

    Regards,

    Yan Li


    Cataleya Li
    TechNet Community Support

    venerdì 26 aprile 2013 05:27
    Moderatore
  • Hi Yan Li,

    Thanks for your help but I saw this thread and it didn't help me. This answer describes how to use higher version of PowerShell but I have to use lesser version (I have to run version 2.0 instead of 3.0).


    Dmitry

    Twitter Lightning Tools LogoLightning Tools Check out our SharePoint tools and web parts | Lightning Tools Blog | Мой Блог

    venerdì 26 aprile 2013 10:14
  • Hi Dmitry, did you ever solve this Problem? I got the same last week.
    sabato 19 ottobre 2019 18:58
  • Hi Dmitry, this is a workaround I am suggesting you. you can pass command or script file as below:

    To execute Command:

    scriptText="powershell.exe -version 2 -ExecutionPolicy ByPass -Command `"<Your Command>`""
    Pipeline pipeline = runspace.CreatePipeline();
        pipeline.Commands.AddScript(scriptText);

    To execute File:

    scriptText="powershell.exe -version 2 -ExecutionPolicy ByPass -File `"<File Name>`""
    Pipeline pipeline = runspace.CreatePipeline();
        pipeline.Commands.AddScript(scriptText);

    lunedì 21 ottobre 2019 16:56