Add-MpPreference 未被识别为名称 [英] Add-MpPreference is not recognized as a name

查看:44
本文介绍了Add-MpPreference 未被识别为名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hello i am doing a small script will run a small powershell using Add-MpPreference. In my case, i was doing because sometimes i want to include some path's in my windows 10 but i must to do manually. So i was trying to make it automatic. I did this:

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

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

What mean's this error? Or can be fixed?

推荐答案

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

I had a similar issue. I discovered that when running Powershell in 32 bit mode on a 64 bit OS it doesn't find the command Add-MpPreference.

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

You can easily recreate this by opening a Powershell console in 32 bit mode and call this function. It will give the same error.

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

The issue occurred because I was running the Powershell script from C# code that was running as 32 bit. This caused the powershell.exe that was called to also be the 32 bit version.

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

I adjusted the code to call the 64 bit version and then the command was found.

为了做到这一点,让它从这里运行 Powershell C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe

In order to do this have it run Powershell from here 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

For more information about how to set the version of powershell visit https://web.archive.org/web/20180314210451/http://www.madwithpowershell.com/2015/06/64-bit-vs-32-bit-powershell.html

这篇关于Add-MpPreference 未被识别为名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆