你好,我正在做一个小脚本,将使用 Add-MpPreference
运行一个小的 powershell。就我而言,我这样做是因为有时我想在我的 Windows 10 中包含一些路径,但我必须手动执行。所以我试图让它自动。我这样做了:
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
这个错误是什么意思?还是可以修复?
最佳答案
我遇到了类似的问题。我发现在 64 位操作系统上以 32 位模式运行 Powershell 时找不到命令 Add-MpPreference。
您可以通过在 32 位模式下打开 Powershell 控制台并调用此函数来轻松地重新创建它。它会给出同样的错误。
出现此问题是因为我从以 32 位运行的 C# 代码运行 Powershell 脚本。这导致调用的powershell.exe也是32位版本。
我调整了代码以调用64位版本,然后找到了命令。
为了做到这一点,让它从这里 C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe 运行 Powershell
有关如何设置 powershell 版本的更多信息,请访问 https://web.archive.org/web/20180314210451/http://www.madwithpowershell.com/2015/06/64-bit-vs-32-bit-powershell.html
关于powershell - Add-MpPreference 未被识别为名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43881583/