Files
Web_BLSKafka_Server_Prod/mypwsh/Program.cs

25 lines
657 B
C#
Raw Normal View History

2025-11-21 08:48:01 +08:00
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!");
}
}
}