初始化
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
15
mypwsh/mypwsh.csproj
Normal file
15
mypwsh/mypwsh.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.1" />
|
||||
<PackageReference Include="System.Management.Automation" Version="7.4.12" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user