Reputation: 13
I am using Powershell to add a Windows Defender exclusion for a file that gets falsely flagged as a workaround. I was testing my script in https://tria.ge and everything worked except the Add-MpPreference commands. I have searched everywhere and found nothing. For me it still works and that is why I am baffled.
The code I am using (snippets):
Show-Status "Adding antivirus exclusion for setup executable.."
Add-MpPreference -ExclusionPath "$SMTTempPath\SMTSetup.exe"
(I then download the file and run the setup)
and
Show-Status "Cleaning up temporary files and antivirus exclusion.."
Remove-Item -Path $SMTTempPath -Recurse -Force
Remove-MpPreference -ExclusionPath "$setupPath"
The variables are properly assigned and work.
Errors I get: On Windows 11:
Add-MpPreference : 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 path was included, verify that the path is correct and try
again.
At C:\Users\Admin\AppData\Local\Temp\getsmt.ps1:70 char:1
+ Add-MpPreference -ExclusionPath "$SMTTempPath\SMTSetup.exe"
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Add-MpPreference:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
and on Windows 10 LSTC:
Add-MpPreference : Operation failed with the following error: 0x800106ba. Operation: MpPreference. Target:
ConfigListExtension.
At C:\Users\Admin\AppData\Local\Temp\getsmt.ps1:70 char:1
+ Add-MpPreference -ExclusionPath "$SMTTempPath\SMTSetup.exe"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_MpPreference:root\Microsoft\...FT_MpPreference) [Add-MpPreference],
CimException
+ FullyQualifiedErrorId : HRESULT 0x800106ba,Add-MpPreference
Add-MpPreference : Operation failed with the following error: 0x%1!x!
At C:\Users\Admin\AppData\Local\Temp\getsmt.ps1:70 char:1
+ Add-MpPreference -ExclusionPath "$SMTTempPath\SMTSetup.exe"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_MpPreference:root\Microsoft\...FT_MpPreference) [Add-MpPreference],
CimException
+ FullyQualifiedErrorId : HRESULT 0x800106ba,Add-MpPreference
What can I do on these machines to make Add-MpPreference and Remove-MpPreference work?
Upvotes: 0
Views: 104