locked
Expose PowerShell as a WCF Service RRS feed

  • Question

  • Hello Group,

    I have been working on automating deployments for various technologies including Dynamic AX, SharePoint, DOTNET, BizTalk and SQL using PowerShell scripts. I got a new requirement from the client, that says the deployment should happen from a Remote Server in a different domain, and an ASP.NET Page to control the entire deployment which would hosted in the Remote Server. Whereas the PowerShell scripts remain in the client servers,

    Requirement

    Host Environment (Server srvHost)

    {

    Domain abc;

    Has the UI (ASP.NET page) developed in DOTNET;

    Should Connect to the server and execute the PowerShell;

    }

     ->

    Target Environment (Server srvClient)

    {

                    Domain xyz;

                    Have the PowerShell scripts to be executed;

    }

    Proposed Solution:

    In the target server (svrClient) expose the PowerShell as a Service and call the service from the Host.

    Problem Statement:

    Is it possible to expose an existing PowerShell script as a WCF/Web service? How?

    Is there a different way in doing all of this?

    Please let me know if you have any confusion around the requirement. Thanks in Advance.

    ~Pattanaik


    Thanks n Regards Biswajit Pattanaik Avanade Technology Group

    Wednesday, May 22, 2013 7:03 PM

Answers


  • Hi Biswajit,

    Based on your description, I understand that your current requirement is to let the ASP.NET server app (central server) to  trigger some powershell script execution on other remote servers (svrClient), correct?

    If this is the case, I think you can consider the following approaches:

    1) Since Powershell naturally supports remote execution, you can tried directly invoking remote script on the ASP.NET server machine against the srvClient machines.

    #How to Execute Remote PowerShell Commands using C#
    http://scorpiotek.com/blog/?p=770

    2) Or if you want to host WCF service on the srvClient machines, you can just use normal Tcp or HTTP based WCF service and  put .NET based powershell execution code in the service operaiton code. So far I haven't found any approach to direclty expose powershell script as a WCF service.

    #How to run PowerShell scripts from C#
    http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 23, 2013 3:55 AM

All replies


  • Hi Biswajit,

    Based on your description, I understand that your current requirement is to let the ASP.NET server app (central server) to  trigger some powershell script execution on other remote servers (svrClient), correct?

    If this is the case, I think you can consider the following approaches:

    1) Since Powershell naturally supports remote execution, you can tried directly invoking remote script on the ASP.NET server machine against the srvClient machines.

    #How to Execute Remote PowerShell Commands using C#
    http://scorpiotek.com/blog/?p=770

    2) Or if you want to host WCF service on the srvClient machines, you can just use normal Tcp or HTTP based WCF service and  put .NET based powershell execution code in the service operaiton code. So far I haven't found any approach to direclty expose powershell script as a WCF service.

    #How to run PowerShell scripts from C#
    http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 23, 2013 3:55 AM
  • Thanks Steven for the quick response. You got the requirement correct. For now I'll go with option 2 as my PowerShell already does PS-Remoting in the srvClient in the same domain.

    Thanks again will keep you posted if I face any difficulty in the implementation.

    ~Pattanaik


    Thanks n Regards Biswajit Pattanaik

    Thursday, May 23, 2013 3:37 PM