I have a powershell script that adds file exclusions to Windows Defender on a computer running Windows 10.
But I run the same script with Windows 8.1 but I get an error message saying:
Add-MpPreference : The 'Add-MpPreference' command was found in the module 'Defender', but the module could not be loaded. For more information, run 'Import-Module Defender'. At line:1 char:1 + Add-MpPreference -ExclusionPath "C:\Temp" + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Add-MpPreference:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
What can I do to make it work with Windows 8/8.1?
Microsoft broke Defender module in 2017-04 Monthly Rollup and later.
Below is C:\WindowsPowerShell\v1.0\modules\Defender\Defender.psd1.
MSFT_MpWDOScan.cdxml and Start-MpWDOScan isn't present in Windows 8.1.
Removing them works again. (This file is protected by TrustedInstaller.)
Alternatively you can copy
MSFT_MpWDOScan.cdxml
from a Windows 10 / 2016 toC:\WindowsPowerShell\v1.0\modules\Defender\
Try with WMI class. I remember there was WMI class exist for defender. Use some WMI tools to explore those classes.