Asp page is not running the Powershell script uisng Invoke-command (script Block) [Answered]RSS

3 replies

Last post Jun 20, 2019 05:49 AM by Jalpa Panchal

  • Asp page is not running the Powershell script uisng Invoke-command (script Block)

    Jun 01, 2019 03:01 PM|Manusan|LINK

    please help if there is any other way i can use the Invoke-command with script block in ASP page

    My powershell script contains , Invoke-command with Script block.  It is not running when it executed by ASP page.

    i have checked the permission and i am executing the asp page using admin access.

    PS script working fine when i run manually and without Invoke-commad , ASP page  is able to call powershell script. 

    My asp page

    string sourceFile = Server.MapPath("/test1.ps1");
    // create Powershell runspace
    var shell = PowerShell.Create();
    shell.Commands.AddScript(@"D:\Inetpub\wwwroot\test1.ps1");
    var results = shell.Invoke();

    My PS script looks like below 

    Invoke-Command -ComputerName $Computername -ScriptBlock {get-childitem IIS:\sites\* }

    </div>

  • Re: Asp page is not running the Powershell script uisng Invoke-command (script Block)

    Jun 03, 2019 05:34 AM|Jalpa Panchal|LINK

    Hi Manoj,

    Did you run "Import-Module WebAdministration" command?

    You could also try to run below command:

    Invoke-Command -ComputerName $server {Import-Module WebAdministration; Get-ChildItem -path IIS:\Sites | Format-Table}

    Regards,

    Jalpa

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: Asp page is not running the Powershell script uisng Invoke-command (script Block)

    Jun 20, 2019 02:47 AM|Manusan|LINK

    Issue fixed by changing IIS application pool identity.

  • Re: Asp page is not running the Powershell script uisng Invoke-command (script Block)

    Jun 20, 2019 05:49 AM|Jalpa Panchal|LINK

    Hi,

    I am glad that you solve your issue with your self.

    I request you to mark the helpful suggestion as an answer. This will help other people who face the same issue.

    Thank you for understanding.

    Regards,

    Jalpa.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.