Implement Powershell in C# code

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

Carlo Goretti

Guest
Hey Guys!

I have tryied to implement this Powershell Code to C#:

$Root = "\";
$Taskname = "L&T Integration"
$Scheduler = New-Object -ComObject Schedule.Service
$Scheduler.Connect()
$RootFolder = $Scheduler.GetFolder($Root)
$Task = $RootFolder.GetTask($Taskname)
$task.LastRunTime
$Task.NextRunTime.DateTime
$task.Enabled
Right now i have this in a seperated script that im reading in..
I want to implement it to c# code so i can set parameters like $TaskName and $Root from C# code..
Here is my C# Code:

string skript = File.ReadAllText(@"C:\Cago\taskSchedulerPS.ps1");
PowerShell ps = PowerShell.Create();
ps.Commands.AddScript(skript);


var resultat = ps.Invoke();


Any Ideas?
Best Regards

Continue reading...
 

Similar threads

C
Replies
0
Views
333
Carlo Goretti
C
C
Replies
0
Views
140
Carlo Goretti
C
C
Replies
0
Views
301
Carlo Goretti
C
Back
Top