![](/img/trans.png)
[英]Powershell commands from C# 'the term is not recognizes as cmdlet'
[英]PowerShell cmdlet Install-WindowsFeature called from C# errors and is not listed in the collections of commands
我正在尝试通过PowerShell和C#在Windows Server 2012系统上安装新功能。 我在尝试调用Install-WindowsFeature
cmdlet时收到此错误:
术语“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:
Invoke-Expression“Powershell -Command {Import-Module ServerManager; Install-WindowsFeature XXXX}”
尝试在x64中编译。 在Visual Studio中,转到菜单项目 → 属性 → 构建 - 平台目标 = x64。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.