I am trying to set the preference DisableRealtimeMonitoring
to false
with the following runspace:
try
{
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
Command setMp = new Command("Set-MpPreference");
string paramRT = "DisableRealtimeMonitoring";
bool pF = Convert.ToBoolean(Convert.ToInt32("0"));
setMp.Parameters.Add(paramRT, pF);
pipeline.Commands.Add(setMp);
runspace.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
This runspace should be the equivalent of the following PS command:
Set-MpPreference -DisableRealtimeMonitoring 0
The PS command works like a charm whilst the runspace code above does not work even if the UAC is disabled. For troubleshooting purpose, I performed some modifications to the code for catching the error which is the following:
The term 'Set-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.
Does anyone know what is wrong in the code?