首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Add-MpPreference未被识别为名称

Add-MpPreference未被识别为名称
EN

Stack Overflow用户
提问于 2017-05-10 07:59:12
回答 1查看 5.1K关注 0票数 3

你好,我正在做一个小脚本,将运行一个使用Add-MpPreference的小powershell。在我的例子中,我之所以这样做,是因为有时我想在我的Windows10中包含一些路径,但我必须手动完成。所以我试着让它自动化。我这样做了:

代码语言:javascript
复制
ShellExecute("powershell", '-noexit Add-MpPreference -ExclusionPath C:/')

错误返回值是我:

代码语言:javascript
复制
The term 'Add-MpPreference' is not recognized as the name of a cmdlet, function
, script file, or operable program. Check the spelling of the name, or if a pat
h was included, verify that the path is correct and try again.
At line:1 char:17
+ Add-MpPreference <<<<  -ExclusionPath C:/
    + CategoryInfo          : ObjectNotFound: (Add-MpPreference:String) [], Co
   mmandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

这个错误是什么意思?或者是可以修复的?

EN

回答 1

Stack Overflow用户

发布于 2017-09-12 10:27:57

我也遇到过类似的问题。我发现在64位操作系统上以32位模式运行Powershell时,它找不到命令Add-MpPreference。

您可以通过以32位模式打开Powershell控制台并调用此函数来轻松地重新创建它。它会给出同样的错误。

出现这个问题是因为我从32位运行的C#代码中运行Powershell脚本。这导致被调用的powershell.exe也是32位版本。

我调整了代码以调用64位版本,然后找到了命令。

为此,让它从这里运行Powershell C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe

有关如何设置powershell版本的更多信息,请访问https://web.archive.org/web/20180314210451/http://www.madwithpowershell.com/2015/06/64-bit-vs-32-bit-powershell.html

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43881583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档