Execute Powershell Script from Script Task

  • Has anyone managed to execute a PoSh script from within a Script Task?

    When I started looking at this, it seemed like it would be straightforward enough and the process is described here.

    But ... the DLL which that article refers to (and which appears to be necessary to execute PoSh from C#) is called System.Management.Automation.dll and, as far as I can see, it is not available by default in the .NET framework. In fact, I could not find it anywhere on my PC.

    As I need to get this done, I am thinking that I will have to change my plans a little to use an Execute Process task to achieve what I want. But I would still like to know whether others have managed this and whether they did so without having to reference an external (and elusive) DLL?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • If it helps, I've found the package on NuGet: https://www.nuget.org/packages/System.Management.Automation/

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thom A wrote:

    If it helps, I've found the package on NuGet: https://www.nuget.org/packages/System.Management.Automation/%5B/quote%5D

    Thanks, Thom. I actually tried that already. It seems that this module works with .NET Core only.

    2020-05-20_10-21-27

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Was worth a go. I've been struggling to install it, as the office's firewall is a real pain; it has to scan every file you download (in full) before you download it and it has no idea what to do with Nuget packages, so it basically refuses to let you download them.

    Guessing that there is an older non .Net Core version, as that is version 7.0.1, but really struggling to find anything prior to 6.0.4 (which is still .Net Core)

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • I think I have that working in one of my packages but through a start process e.g. new process kicked off which starts a new powershell instance.

    if that works for you I can get the code out

  • Thanks to you both for your efforts.

    I now have this working via an Execute Process task (though I still have to do some serious parameterisation to make it production-ready).

    So I'm happy to let it go. Let's hope that a version of that library is added to the .NET framework at some point, because it would be useful to have the ability to do this, without having to faff around so much.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • I may be wrong - but installing POsh 5.1 should contain the automation namespace - and this will not be .net core

    https://www.microsoft.com/en-us/download/details.aspx?id=54616

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply