malwarebytes-4.jpg

Deploying MalwareBytes Anti-Malware Utility with PowerShell

Deploying MalwareBytes Anti-Malware Utility with PowerShell

malwarebytes-4.jpg

Here is how you can deploy MalwareBytes, a popular anti-malware tool, quickly and inexpensively on multiple machines at once with PowerShell. 

All software deployments essentially have three different components; delivery, local execution, and reporting. Delivery is sending the installer(s) to remote systems; local execution means running the installer or script on these systems, and reporting is somehow logging the behavior of the install. Software deployments are similar, but no two are the same due to each piece of software's unique way of needing to be installed. The popular anti-malware utility MalwareBytes is no different.

The first task is downloading the installer. Once you've downloaded the installer, the next step is figuring out a way to get it delivered to each system you'd like to install it on. There are numerous ways to do this and various tools like Microsoft's System Center Configuration Manager (SCCM) or Dell KACE. But these system management services can be costly. For our purposes we're going to do this inexpensively with PowerShell.

 

I'll start building a script called Install-MalwareBytes.ps1 to get this software deployed. I'll first create an array of computer names I'd like to install MalwareBytes on. I'll then create a foreach loop and copy the installer folder to each of the computers.

$computers = 'PC1','PC2','PC3'
foreach ($computer in $computers) {
    Copy-Item -Path C:\MalwareBytesInstaller -Destination "\\$computer\c$"
}

Each computer should now have a C:\MalwareBytesInstaller folder with the installer inside. Next, we'll use PowerShell remoting to remotely invoke the installer on each computer. I'm assuming here that you have permission to remotely connect to each of these machines and you have PowerShell remoting enabled and available on each. Adding to our script, I'll use Invoke-Command to remotely invoke the Malwarebytes installer using the appropriate silent install switches.

$computers = 'PC1','PC2','PC3'
foreach ($computer in $computers) {
    Copy-Item -Path C:\MalwareBytesInstaller -Destination "\\$computer\c$"
    Invoke-Command -ComputerName $computer -ScriptBlock { C:\MalwareBytesInstaller\}Mbam-setup.exe /SILENT /NORESTART }
}

This should get MalwareBytes installed on each of the computers we've targeted. However, we can't be sure until we check.

Related Article: How To Use PowerShell To Monitor REST APIs

To do this, I've chosen to incorporate a free PowerShell module I've created called SoftwareInstallManager. It can be downloaded directly from Github or via Install-Module SoftwareInstallManager. This is a set of modules that allows you to do lots of different tasks around software deployments. One of those tasks is finding installed software using the Get-InstalledSoftware command. But to use it, it must be copied to each computer. Since we're already copying the installers over, adding these modules should be no sweat.

$computers = 'DC'
foreach ($computer in $computers) {
    Copy-Item -Path C:\MalwareBytesInstaller -Destination "\\$computer\c$" -Recurse -Force
    Copy-Item -Path C:\SoftwareInstallManager -Destination "\\$computer\c$" -Recurse -Force
    Invoke-Command -ComputerName $computer -ScriptBlock {
        C:\MalwareBytesInstaller\mb3-setup-consumer-3.0.6.1469-10103.exe /SILENT /NORESTART
        Import-Module C:\SoftwareInstallManager\1.0.0.0\SoftwarInstallManager.psd1
        if (Get-InstalledSoftware | where { $_.Name -match 'MalwareBytes' }) {
            [pscustomobject]@{
                ComputerName = (hostname)
                Result = $true
            }
        } else {
            [pscustomobject]@{
                ComputerName = (hostname)
                Result = $false
            }
        }
    } | Select ComputerName,Result
}

At this point, my script is going to return an object for each computer after Malwarebytes is installed indicating if it was successful or not.

ComputerName Result
------------ ------
PC1            False
PC2            True
PC3            True

And there you have it. You've succesfully installed MalwareBytes on all targeted machines. 


Comments
Comments are disabled in preview mode.
Loading animation