你好,我正在做一个小脚本,将运行一个使用Add-MpPreference的小powershell。在我的例子中,我之所以这样做,是因为有时我想在我的Windows10中包含一些路径,但我必须手动完成。所以我试着让它自动化。我这样做了:
ShellExecute("powershell", '-noexit Add-MpPreference -ExclusionPath C:/')错误返回值是我:
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这个错误是什么意思?或者是可以修复的?
发布于 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
https://stackoverflow.com/questions/43881583
复制相似问题