Prerequisite:
1) WGET for Windows: http://users.ugent.be/~bpuype/wget/
2) Setting your PowerShell Execution Policy to Unrestricted by:
Set-ExecutionPolicy Unrestrictedor 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).osarchitectureand you can automate this by creating a task in task manager to run this script as often as you want.
$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"
}
}
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 :
ReplyDelete$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)
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