locked
Powershell script not working under IIS hosting RRS feed

  • Question

  • User-1404113929 posted

    Hello All,

    I have created one application which is executing the PowerShell script and displayed result as well , it is working in iis express but when I try to host application in IIS the powershell script is notworking.

    please help us.

    code:

    PowerShellInstance = PowerShell.Create();

    PowerShellInstance.AddScript("Login-AzureRmAccount");
    Collection<PSObject> PSOutput = PowerShellInstance.Invoke();

    Thanks,

    Murali

    Friday, June 8, 2018 6:19 AM

Answers

  • User753101303 posted

    Ok. Does it show a popup locally ? If yes it can't work this way and you would have to pass credentials so that no user action is required when the command runs.

    It might be a start but depending on what to do next rather than using PowerShell commands, you could perhaps use the Azure or Graph API ? See https://docs.microsoft.com/en-us/rest/api/azure/ which should be usable through https://www.nuget.org/packages/Microsoft.WindowsAzure.Management.Libraries

    Finally if you have an error, it's best to tell which error you have (you may need a runspace, if I remember you may have something to enable first or you could have a PowerShell version issue etc...) so it"s always best to start from the EXACT error you have rather than trying to figure out which error you have by reading the code (it's not rare that even for few line of codes you could have multiple things that could go wrong).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 8, 2018 11:38 AM

All replies

  • User753101303 posted

    Hi,

    It shows an authentication prompt locally ? Keep in mind this code runs server side so it would "show" this on the web server where nobody could interact with that prompt so stricly speaking I'm not sure this code will ever be able to work as you want. What are you trying to do ?

    Friday, June 8, 2018 9:21 AM
  • User-1404113929 posted

    Hi,

    I want to display vm admin users list.

    Friday, June 8, 2018 10:49 AM
  • User753101303 posted

    Ok. Does it show a popup locally ? If yes it can't work this way and you would have to pass credentials so that no user action is required when the command runs.

    It might be a start but depending on what to do next rather than using PowerShell commands, you could perhaps use the Azure or Graph API ? See https://docs.microsoft.com/en-us/rest/api/azure/ which should be usable through https://www.nuget.org/packages/Microsoft.WindowsAzure.Management.Libraries

    Finally if you have an error, it's best to tell which error you have (you may need a runspace, if I remember you may have something to enable first or you could have a PowerShell version issue etc...) so it"s always best to start from the EXACT error you have rather than trying to figure out which error you have by reading the code (it's not rare that even for few line of codes you could have multiple things that could go wrong).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 8, 2018 11:38 AM