Help with running import-module command on remote computers

Hello,
I am trying to get a scheduled task together to check antivirus on servers by using get-mpcomputerstatus.
The script i currently works for 2016 and 2019, but not for 2012. 2012 uses get-mprotcomputerstatus, but only if i enable the module using:
Import-Module “$env:ProgramFiles\Microsoft Security Client\MpProvider”
I have almost 600 2012 servers, so trying to enable this module on all of them with a script.

I’ve tried;

$Session = Start-PSSession -ComputerName server1
Invoke-Command -Session $Session -ScriptBlock { Import-Module “$env:ProgramFiles\Microsoft Security Client\MpProvider” }
Import-PSSession $Session

Invoke-Command -computername "server1" -ScriptBlock Import-Module “$env:ProgramFiles\Microsoft Security Client\MpProvider” -Credential $cred

So far, neither of these work. The script runs without error, but spot checking on some servers by running get-command -module mpprovider, nothing is there still.

Any help would be appreciated.

Did I get this right … you can import the module locally on the server and your query works this way?! :thinking:

So why don’t you add the command to import the module explicitly to the script you’re using to query those old servers?

If I go to a 2012 server and run the Import-Module command, it works. I am then able to run get-mprotcomputerstatus and see the details of the antivirus.

Your suggesting adding:
Import-Module “$env:ProgramFiles\Microsoft Security Client\MpProvider”

Before my script of checking for status?

$defenderStatus = Get-MprotComputerStatus | select AntivirusEnabled, AntivirusSignatureLastUpdated, AntivirusSignatureVersion, QuickScanEndTime, RealTimeProtectionEnabled

Ugh…
It’s amazing how simple the fix is sometimes because you get stuck in one train of thought.

That worked.

Thank you very much for all you do.

To be unable to see the forest for the trees happens to all of us sometimes. :wink:

1 Like