System.Management.Automation.Powershell Class

Hey everyone, I'm new/learning C#. I have experience with powershell so its not a difficult learning curve. I'm trying to kick off a powershell script that will start powershell as admin. In powershell it would simply be:

Start-Process -file Powershell.exe -argumentlist "c:\script.ps1" -verb runas

I've gotten it to kick off a test script by doing the following:

using(Powershell ps = Powershell.Create()) { ps.AddScript("c:\script.ps1"); ps.Invoke(); }

But the script I need to run as admin is failing. I'm currently trying:

using(Powershell ps = Powershell.Create()) { ps.AddCommand("Start-Process"); ps.AddParameter("file"); ps.AddArgument("Powershell.exe"); ps.AddParameter("Argumentlist"); ps.AddArgument("c:\script.ps1"); ps.AddParamer("verb"); ps.AddArgument("runas"); ps.Invoke(); }

Any tips, advice, or criticism would be greatly appreciated.

by guido_marx via /r/csharp

Leave a Reply