初始化
This commit is contained in:
24
mypwsh/Program.cs
Normal file
24
mypwsh/Program.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Runspaces;
|
||||
namespace mypwsh
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
using (var ps = PowerShell.Create())
|
||||
{
|
||||
// 避免使用 AddScript,改用 AddCommand
|
||||
ps.AddCommand("Get-Service");
|
||||
|
||||
var results = ps.Invoke();
|
||||
foreach (var result in results)
|
||||
{
|
||||
var service = result.BaseObject;
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user