I have a problem that i have been googling on for hours and hours.
I try to run a remote Powershell script to start up a process. Exit and then let it run. It takes hours. The problem is that the process seem to exit directly after beeing started, without errors or any information in logs.
I know it starts, it create the logfile specified (but empty) and i get a response from Start-Process with process id and other information. If i take the script and paste it inside a Powershell command window on the client in question. It runs without any problems. So the script does not seem to be faulty.
Im new to this so bear with me.
InitialSessionState initial = InitialSessionState.CreateDefault();
initial.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Unrestricted;
Runspace runspace = RunspaceFactory.CreateRunspace(initial);
runspace.Open();
var ps = PowerShell.Create();
ps.Runspace = runspace;
ps.AddCommand("Invoke-Command");
ps.AddParameter("ComputerName", Host);
ps.AddParameter("Credential", CreateCredentials());
ScriptBlock filter = ScriptBlock.Create(command);
ps.AddParameter("ScriptBlock", filter);
Collection<PSObject> results = ps.Invoke();
return results;
My command line that i pass lookes like this:
Start-Process -FilePath C:\Some\Valid\Path\prog.exe -ArgumentList "Long list of arguments specific to exe" -PassThru -RedirectStandardOutput C:\Log\Path\current.log
Does someone have any ideas, what im i missing?