Add-MpPreference无法识别为名称

Sir*_*ack 2 powershell

您好,我正在做一个小的脚本,它将使用来运行一个小的powershell Add-MpPreference。就我而言,我这样做是因为有时我想在Windows 10中包含一些路径,但是我必须手动执行。所以我试图使其自动化。我这样做:

ShellExecute("powershell", '-noexit Add-MpPreference -ExclusionPath C:/')
Run Code Online (Sandbox Code Playgroud)

错误返回是我:

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
Run Code Online (Sandbox Code Playgroud)

这是什么意思?还是可以解决?

小智 5

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

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

发生问题是因为我从32位C#代码运行Powershell脚本。这导致被称为也是32位版本的powershell.exe。

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

为了执行此操作,请从此处运行Powershell C:\ Windows \ SysNative \ WindowsPowerShell \ v1.0 \ powershell.exe

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