#########################################################################################
#                                                                                        #
#    NAME: Update Information Script                                                        #
#    VERSION: 1                                                                            #
#    CODE BY: Jesse Hamrick – http://www.powershellpro.com                                #
#    AUTHOR: Arjen Huitema                                                                #
#    DATE: 05-12-2011                                                                    #
#    COMMENT: To run the code below make sure your computer has Excel and MBSA installed    #
#                                                                                        #
#########################################################################################

# Variables.
$strComputer = Read-Host “Enter Computer Name”
$strDomain = Read-Host “Enter the Domain Name”

# Default Install Path for MBSA 2.1. If your install path is different, change line below.
$Path = “C:Archivos de programaMicrosoft Baseline Security Analyzer 2"

# Create new com object Excel
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

# Assign each worksheet to a variable and name the worksheet.
$Sheet1 = $Excel.Worksheets.Item(1)
$Sheet1.Name = “Patches”

#Create Heading for Anti-Virus Sheet
$Sheet1.Cells.Item(1,1) = “Computer Name”
$Sheet1.Cells.Item(1,2) = “Patch Information”

$intRow = 2
$WorkBook = $sheet1.UsedRange
$WorkBook.Interior.ColorIndex = 20
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True

Set-Location $Path
$cmd = “cmd /c mbsacli.exe /Target $strDomain$strComputer /n OS+SQL+IIS+Password >C:MBSA$strComputer.txt”
Invoke-Expression $cmd

$logResults = (Get-Content “C:MBSA$strComputer.txt”) -match “Missing”
foreach($Item in $logResults){
$Sheet1.Cells.Item($intRow, 1) = $strComputer
$Sheet1.Cells.Item($intRow, 2) = $Item
$intRow = $intRow + 1
}

#Auto Fit all sheets in the Workbook
$WorkBook = $colorItem.UsedRange
$WorkBook.EntireColumn.AutoFit()
clear

#delete Temp File
Remove-Item “C:MBSA$strComputer.txt”