【发布时间】:2019-04-30 19:58:50
【问题描述】:
我想从我的 C# 应用程序中运行以下 powershell 命令:
Enter-PSSession –ComputerName fedsrv01.domain.local
Start-ADSyncSyncCycle -PolicyType Delta
我找到了一些有关 Powershell 类的信息,但由于缺乏经验而难以实现我想要的。
这是我目前所拥有的:
我已经添加了程序集并引用了 system.management.automation
using (var powershell = PowerShell.Create())
{
//powershell.AddCommand("get-process");
powershell.AddCommand("Enter-PSSession -ComputerName fedsrv01.domain.local");
powershell.Invoke();
}
我收到一条错误消息,'The term 'Enter-PSSession -ComputerName fedsrv01.domain.local' is not recognized as the name of a cmdlet, function, script file, or operable program.
如果我使用:powershell.AddCommand("get-process"),它执行得很好。
如果我在同一台 PC 上启动 Powershell 并输入,Enter-PSSession -ComputerName fedsrv01.domain.local 它工作正常。
任何帮助将不胜感激。
干杯,
乔诺
【问题讨论】:
标签: c# powershell