从 C# 错误调用的 PowerShell cmdlet Install-WindowsFeature 未列在命令集合中 [英] PowerShell cmdlet Install-WindowsFeature called from C# errors and is not listed in the collections of commands

查看:43
本文介绍了从 C# 错误调用的 PowerShell cmdlet Install-WindowsFeature 未列在命令集合中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 PowerShell 和 C# 在 Windows Server 2012 系统上安装新功能.尝试调用 Install-WindowsFeature cmdlet 时出现此错误:

I'm trying to install new features on a Windows Server 2012 system through PowerShell and C#. I am getting this error back when trying to call the Install-WindowsFeature cmdlet:

术语Install-WindowsFeature"不被识别为cmdlet、函数、脚本文件或可运行的程序...

The term 'Install-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable program...

我可以通过 C# 调用其他 cmdlet,甚至可以调用其他一些新的 cmdlet.我做了一个 Get-CommandInstall-WindowsFeatureRemove-WindowsFeatureGet-WindowsFeatures 没有列出...但大约 980 人是.

I can call other cmdlets though C# and even some of the other new ones. I did a Get-Command and Install-WindowsFeature, Remove-WindowsFeature, and Get-WindowsFeatures are not listed...but about 980 others are.

为什么我不能从我的 C# 程序调用这个 cmdlet,但是当我去 PowerShell 时它调用它就好了?

Why wouldn't I be able to call this cmdlet from my C# program, but when I go to PowerShell it calls it just fine?

runspace = RunspaceFactory.CreateRunspace();
runspace.Open();

Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Install-WindowsFeature");
Collection<PSObject> output = pipeline.Invoke();

推荐答案

尝试在 x64 中编译.在 Visual Studio 中,转到菜单 ProjectPropertiesBuild - Platform Target = x64.

Try compiling in x64. In Visual Studio go to menu ProjectPropertiesBuild - Platform Target = x64.

这篇关于从 C# 错误调用的 PowerShell cmdlet Install-WindowsFeature 未列在命令集合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆