C# Code example that runs Powershell on Windows VM to call Python scripts -- 2

Job ID: 32990868

Budget: $30 – $250 USD

Need working example of C# code that instantiates Powershell on an Azure Windows server 2019 Datacenter VM. Powershell needs to successfully run Python scripts on the server. Currently, the C# code that successfully works on a development laptop does not work on the Azure/Windows server. I presume this is a user policy or execution permission issue. You (the Freelancer) need to know how to circumvent this issue. It’s not the actual script Powershell or Python scripts that are needed, just the know-how to get them running on Windows Server 2019 (Azure)

Here are examples of the two methods we have tried. Both worked locally but failed on server.

Powershell Object method
PowerShell ps = PowerShell.Create();
ps.AddScript(@"cd:\\Users\\vmname\\Documents " );
ps.AddScript(@"python .\python_script.py" );
ps.Invoke();


Process Method
Process process = new Process();
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.CreateNoWindow = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
process.StandardInput.WriteLine(@"cd:\\Users\\vmname\\Documents“);
process.StandardInput.WriteLine(@"python .\python_script.py ");