We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

View Complete Thread
  • 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();
    var results = shell.Invoke();

    My PS script looks like below 

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