我正在尝试通过 PowerShell 和 C# 在 Windows Server 2012 系统上安装新功能。尝试调用 Install-WindowsFeature
cmdlet 时出现此错误:
我可以通过 C# 调用其他 cmdlet,甚至可以调用其他一些新的 cmdlet。我做了一个 Get-Command
和 Install-WindowsFeature
、 Remove-WindowsFeature
和 Get-WindowsFeatures
没有列出......但大约 980 其他是。
为什么我不能从我的 C# 程序调用这个 cmdlet,但是当我去 PowerShell 时它调用它就好了?
runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Install-WindowsFeature");
Collection<PSObject> output = pipeline.Invoke();
最佳答案
在您的代码中尝试使用此命令而不是 Install-WindowsFeature:
关于c# - 从 C# 错误调用的 PowerShell cmdlet Install-WindowsFeature 未列在命令集合中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13021547/