powershell - Add-MpPreference 未被识别为名称

标签 powershell

你好,我正在做一个小脚本,将使用 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/

相关文章:

programming-languages - 这个概念的名称是什么?

powershell - winpe 的 BCD 条目仅启动准备自动修复

json - Azure 管理服务 - 类型转换错误(NSG 安全规则)

powershell - 使用PowerShell更改AD中电话号码的格式

powershell - 为什么我不能从 WMI 中选择 AliasProperty?

c# - 术语 'Add-AzureAccount' 未被识别为 cmdlet、函数、脚本文件的名称

sql - Oracle 插入中缺少逗号

powershell - Get-AdComputer -filter 参数不接受 Get-Date 输出

powershell - 如何使用 PowerShell 将当前日期计算为自 1601-01-01 以来的毫秒数

PowerShell 函数返回 DataTable 中的重复项