Вопрос

From My MVC4 page I need to call a Powershell script. I don't really need to return any result from it, just make sure the script runs.

When I Debug in my computer, it works fine, but when I try after publishing, it just doesn't do anything or show any error.

This is the code in my Controller:

using (new Impersonator(ConfigurationManager.AppSettings["ImpersonatorUser"], 
                        ConfigurationManager.AppSettings["ImpersonatorDomain"], 
                        ConfigurationManager.AppSettings["ImpersonatorPassword"]))
{
    var scr = new PSScriptParam("\\\\SERVER\\...\\Script.ps1", Param);
    scr.Run();
}

The class PSScriptParam is just this:

public class PSScriptParam
{
    public string Script { get; set; }
    public string Param { get; set; }

    public PSScriptParam(string Path, string param)
    {
        Param = param;
        Script = Path;
    }

    public void Run()
    {

        try
        {
            Process _Proc = Process.Start("Powershell.exe", Script + " '" + Param + "'");

        }

        catch (Exception err)
        {
            System.IO.File.WriteAllText("\\\\SERVER\\...\\Error.txt", err.Message.ToString());
        }

    }
}

The impersonator is using a domain admin account, and the execution policy is set as unrestricted in the server (there is no problem running the script from the cmd).

Can anyone help?

Thanks in advance!

Это было полезно?

Решение

This problem was solved after applying pending updates in the server... Even if I'm not sure why it didn't work, updating Windows solved the problem.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top