Execute powershell script from C#

  • Thread starter Thread starter Carlo Goretti
  • Start date Start date
C

Carlo Goretti

Guest
Hey Guys! Im trying to execute a powershell script from my C# program but dosent get it to work.. the script works fine in powershell but C# dont want to use it.. Any ideas?

Here is my C# code:


PowerShell ps = PowerShell.Create();
ps.Commands.AddScript(@"C:\Cago\powershell.ps1");
var resultat = ps.Invoke();

I just want to se that "resultat" gets something.. But its allways 0..
Here is my powershell code:

$Scheduler = New-Object -ComObject Schedule.Service
$Scheduler.Connect()
$RootFolder = $Scheduler.GetFolder("\")
$Task = $RootFolder.GetTask("testaktivitet")
$task.LastRunTime
#$Task.NextRunTime

Continue reading...
 

Similar threads

C
Replies
0
Views
335
Carlo Goretti
C
C
Replies
0
Views
142
Carlo Goretti
C
C
Replies
0
Views
101
Carlo Goretti
C
Back
Top