-->

Does Add-MpPreference work with Windows 8.1?

2019-06-10 03:19发布

问题:

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?

回答1:

Try with WMI class. I remember there was WMI class exist for defender. Use some WMI tools to explore those classes.



回答2:

Microsoft broke Defender module in 2017-04 Monthly Rollup and later.
Below is C:\WindowsPowerShell\v1.0\modules\Defender\Defender.psd1.

@{
GUID = 'C46BE3DC-30A9-452F-A5FD-4BF9CA87A854'
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="ゥ Microsoft Corporation. All rights reserved."
ModuleVersion = '1.0'
NestedModules = @( 'MSFT_MpComputerStatus.cdxml',
                   'MSFT_MpPreference.cdxml',
                   'MSFT_MpThreat.cdxml',
                   'MSFT_MpThreatCatalog.cdxml',
                   'MSFT_MpThreatDetection.cdxml',
                   'MSFT_MpScan.cdxml',
                   'MSFT_MpSignature.cdxml',
                   'MSFT_MpWDOScan.cdxml')


AliasesToExport = @()
FunctionsToExport = @( 'Get-MpPreference',
                       'Set-MpPreference',
                       'Add-MpPreference',
                       'Remove-MpPreference',
                       'Get-MpComputerStatus',
                       'Get-MpThreat',
                       'Get-MpThreatCatalog',
                       'Get-MpThreatDetection',
                       'Start-MpScan',
                       'Update-MpSignature',
                       'Remove-MpThreat',
                       'Start-MpWDOScan')

PowerShellVersion = '3.0'
HelpInfoUri="http://go.microsoft.com/fwlink/?linkid=390762"
}

MSFT_MpWDOScan.cdxml and Start-MpWDOScan isn't present in Windows 8.1.
Removing them works again. (This file is protected by TrustedInstaller.)



回答3:

Alternatively you can copy MSFT_MpWDOScan.cdxml from a Windows 10 / 2016 to C:\WindowsPowerShell\v1.0\modules\Defender\