Deploying MalwareBytes Anti-Malware Utility with PowerShell

Deploying MalwareBytes Anti-Malware Utility with PowerShell

Posted on May 23, 2017 0 Comments

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. 

Adam Bertram

Adam Bertram is a 20-year veteran of IT. He’s currently an automation engineer, blogger, independent consultant, freelance writer, author, and trainer. Adam focuses on DevOps, system management, and automation technologies as well as various cloud platforms. He is a Microsoft Cloud and Datacenter Management MVP and efficiency nerd that enjoys teaching others a better way to leverage automation.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation