Monday, November 30, 2009

MS Security Essentials PowerShell Updater

I have MS Security Essentials (MSSE) installed on my netbook and was looking on bing/google on any scripts/apps that will update it more often and not through Microsoft Update (MU). I stumbled upon: http://social.answers.microsoft.com/Forums/en-US/mseupdate/thread/ef8051c7-b133-4cd5-ab32-ca10d61fe223 and got me thinking on how can I do the same thing a bit better and in powershell-style than command/batch scripting.

Prerequisite:
1) WGET for Windows: http://users.ugent.be/~bpuype/wget/
2) Setting your PowerShell Execution Policy to Unrestricted by:
Set-ExecutionPolicy Unrestricted
or put this into a cmd/batch file:
powershell.exe -ExecutionPolicy unrestricted -file Update-MSSE.ps1

The Actual powershell script, Update-MSSE.ps1:
$arch = (gwmi win32_operatingsystem).osarchitecture
$pth ="D:\" #set to the path where wget.exe is stored
$dwnld = "false"
$lnkID = "0"

if ($arch -eq "32-bit"){
$lnkID = "87342"
$dwnld = "True"
} elseif ($arch -eq "64-bit") {
$lnkID = "87341"
$dwnld = "True"
} else {
echo "Error! OS Architecture not found!"
pause
break
}

if ($dwnld -eq "true"){
Start-Process -wait cmd.exe -ArgumentList ("/c " + $pth + "wget.exe -q -N http://go.microsoft.com/fwlink/?LinkID="+$lnkID)
if ((Test-Path .\mpam-fe.exe) -eq "True") {
Start-Process -wait .\mpam-fe.exe -ArgumentList "-q"
} elseif ((Test-Path .\mpam-fex64.exe) -eq "True") {
Start-Process -wait .\mpam-fex64.exe -ArgumentList "-q"
}
}
and you can automate this by creating a task in task manager to run this script as often as you want.

2 comments:

  1. Good stuff. Two small suggestions: First use RemoteSigned, this is a middle ground between Unrestricted and AllSigned that will prevent potentially unsafe scripts from running, but still allow you to run scripts without signing. Second instead of relying on wget which may or may not be available on a machine take a look at the native .NET class System.Net.WebClient :

    $url = "http://go.microsoft.com/fwlink/?LinkID=87342"
    $client = new-object System.Net.WebClient
    $target = "C:\Users\u00\Downloads\mpam-fe.exe"
    $client.DownloadFile($url,$target)

    ReplyDelete
  2. Thanks Chad for the comments, the main reason behind wget for now is the -N flag, "don't re-retrieve files unless newer than local." still looking into on how-to the same thing under webclient class

    ReplyDelete