Malicious Software Removal Tool Disable/Uninstall
Summary
This script disables and uninstalls the MSRT from the endpoint and provided option to creates ticket if failure detected. It also save result to the custom field MSRT Scanner Result
so that the agent gets excluded from the dynamic group Malicious Software Removal Tool Uninstall-Disable group if the task ran successfully.
This script can be on demand as well or by scheduling it to the group Malicious Software Removal Tool Uninstall-Disable group.
Dependencies
Sample Run
Check the Create Ticket
flag option if you want to create ticket for the endpoint during failure and if you do not want to uninstall the MSRT KB890830 then change the MSRTUninstall
value from 1 to anything and then click Continue to Scheduling
.
Click Run Task
Implementation
Create Task
Malicious Software Removal Tool Disable/Uninstall
To implement this script, please Add Parameter
first:
Click Add Parameter
on the top right side of the new script:
Set parameter CreateTicket
as a flag with Default Value
set to False
and do not turn on the Required Field
. This is set to not create a ticket by default, if required to create ticket on failure change the default value to True
.
Add second parameter MSRTUninstall
as a Number Value with Default Value
set to 1
and do not turn on the Required Field
. This is set to uninstall the MSRT patches if already installed, if not required to uninstall the patch change the default value to anything other than 1.
To implement this script, please create a new "PowerShell" style script in the system.
- Name: Malicious Software Removal Tool Disable/Uninstall
- Description: This script disables and uninstalls the MSRT from the endpoint and provided option to creates ticket if failure detected. Based on the output, it sets the custom field
MSRT Scanning Result
. - Category: Security
Script
Start by creating a row. You can do this by clicking the "Add Row" button at the bottom of the script page.
Row 1: Function: Pre-defined Variable
Paste the highlighted text:
Variable Name: Systemname
System Variable: Drop down Endpoint>Asset>Friendlyname
Row 2: Function: PowerShell Script
Paste in the following PowerShell script and set the expected time of script execution to 600
seconds.
### Region Strapper ###
$ProgressPreference = 'SilentlyContinue'
[Net.ServicePointManager]::SecurityProtocol = [Enum]::ToObject([Net.SecurityProtocolType], 3072)
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
try {
Update-Module -Name Strapper -ErrorAction Stop
}
catch {
Install-Module -Name Strapper -Repository PSGallery -SkipPublisherCheck -Force
Get-Module -Name Strapper -ListAvailable | Where-Object { $_.Version -ne (Get-InstalledModule -Name Strapper).Version } | ForEach-Object { Uninstall-Module -Name Strapper -MaximumVersion $_.Version }
}
(Import-Module -Name Strapper) 3>&1 2>&1 1>$null
(Set-StrapperEnvironment) 3>&1 2>&1 1>$null
$Path = 'HKLM:\SOFTWARE\Policies\Microsoft\MRT'
$Name = 'DontOfferThroughWUAU'
$KBNumber = '890830'
try {
# Check if the registry path exists; if not, create it
if (-not (Test-Path $Path)) {
New-Item -Path $Path -Force
}
# Set the registry key value
Set-ItemProperty -Path $Path -Name $Name -Value 1 -Type DWord -Force
Write-Output 'Registry key set successfully.'
Write-Log 'Registry key set successfully.' -Level Information
#Check if MSRT Uninstall Approved
$MSRTUninstall = '@MSRTUninstall@'
if ($MSRTUninstall -eq 1) {
Write-Output 'MSRT Uninstall Approved'
Write-Log 'MSRT Uninstall Approved'
# Check if MSRT is installed
$msrtInstalled = Get-HotFix -Id $KBNumber -ErrorAction SilentlyContinue
if ($msrtInstalled) {
# Uninstall MSRT
$uninstallProcess = Start-Process -FilePath "wusa.exe" -ArgumentList "/uninstall /kb:$KBNumber /quiet /norestart" -Wait -PassThru
if ($uninstallProcess.ExitCode -eq 0) {
Write-Output 'MSRT uninstalled successfully.'
Write-Log 'MSRT uninstalled successfully.' -Level Information
}
else {
Write-Output "An error occurred: MSRT uninstallation failed with exit code $($uninstallProcess.ExitCode)."
Write-Log "An error occurred: MSRT uninstallation failed with exit code $($uninstallProcess.ExitCode)." -Level Error
}
}
else {
Write-Output 'MSRT is not installed on this system.'
Write-Log 'MSRT is not installed on this system.' -Level Information
}
}
else {
Write-Output 'MSRT Uninstall is suspended'
Write-Log 'MSRT Uninstall is suspended' -Level Information
}
}
catch {
Write-Output "An error occurred: $_"
Write-Log "An error occurred: $_" -Level Error
}
Row 3: Logic: If/Then
Row 3a: Condition: Output Contains
In the IF part, enter An error occurred
in the right box of the "Output Contains" part.
Row 3b: Function: Set Custom Field
Add a new row by clicking on the Add row button and select Set Custom Field
.
Clicking Set Custom Field
opens up new window.
Custom Field: MSRT Scanner Result
Value: MSRT Disable Failed
Row 3c(i): Logic: If/Then
Row 3c(ii): Condition: Value
In the IF part, enter @CreateTicket@
in the right box of the "Value contains" part where Value 1
Equals
to @CreateTicket@
.
Row 3c(iii): Function: Create Ticket
Add a new row by clicking on the Add row button.
Select Function 'Create Ticket'. When you select Create Ticket
, it will open up a new window.
In this window, set the Subject
as Malicious Software Removal Tool Disable failed on computer: @SystemName@ of company: %companyname%
.
Body
as Malicious Software Removal Tool Disable failed on the endpoint. Refer to the logs: %output%
Priority
set to Low
Row 3d: Function: Script Exit
Add a new row in the If section and select Script Exit
.
In the script exit message, simply type Script failed to disable the Malicious Software Removal Tool. Exiting script with error. Refer to the logs: %Output%
.
In the script exit message, leave it blank.
Row 4: Function: Set Custom Field
Add a new row after End If
section by clicking on the Add row button and select Set Custom Field
.
.
Custom Field: MSRT Scanner Result
Value: MSRT Disabled
Row 5: Function: Script Log
In the script log message, simply type Malicious Software Removal Tool disabled successfully. Refer to the logs: %Output%
so that the script will send the results of the PowerShell script above to the output on the Automation tab for the target device.
Row 6: Complete
Deployment
It is suggested to run the Task every 2 hours against the group Malicious Software Removal Tool Uninstall-Disable group
- Go to
Automation
>Tasks.
- Search for
Malicious Software Removal Tool Disable/Uninstall
Task. - Select the concerned task.
- Click on the
Schedule
button to schedule the task/script.
Select the relevant time to run the script and click the Do not repeat button.
A pop-up box will appear.
Change the number of hours to 2
and click OK
.
Select the target Device Group
to schedule on the group Malicious Software Removal Tool Uninstall-Disable group.
Now click the Run
button once all customization is set to initiate the task.
The task will start appearing in the Scheduled Tasks.
Output
- Task log