"Trying to script a check for MS17 010 patches"

I'm not sure what I need to change as this isn't working for me. "Unknown Error"

$hotfixes = "KB4012212", "KB4012217", "KB4015551", "KB4019216", "KB4012216", "KB4015550", "KB4019215", "KB4013429", "KB4019472", "KB4015217", "KB4015438", "KB4016635"

$computer = $ENV:COMPUTERNAME

$hotfix = Get-HotFix -ComputerName $computer |
Where-Object {$hotfixes -contains $_.HotfixID} |
Select-Object -property "HotFixID"

if($hotfix) {
Write-Output "$computer has hotfix $hotfix installed"
} else {
Write-Output "$computer is missing hotfix"
}

created 11 days ago
CCWTechnology
 21 1 2
You must be signed in before you can post a fix

Comments:

You need to run an admin command prompt cscript fix-877.vbs 4019472 4013198 -param01 -logfile . This works for us we get a new line with the hotfix with number #### is installed or is NOT installed. DigitAL3X 9 days ago
Where do you input the variables? I cannot figure this out, please let me know as soon as you can if possible. I would really like to use this. androidontherun 9 days ago
cancel
Scripting Language: VBScript

FAST VBscript to check if one or more hotfix is installed on localhost

works on all Windows version

please test before use it

to check for wannacry insert all KB number as paramenters

https://status.solarwindsmsp.com/2017/05/15/ransomware-attack-how-to-verify-if-your-devices-are-fully-protected-against-wannacry-ransomware/

to test from elevated cmd run

cscript chk-hotfix.vbs 4012598 4012212 4012215 4012598 4012213 4012216 4012214 4012217 4012606 4013429 4015217 4013198 -param1 -logfile

The script fails even if a hotfix is ​​not instelled

The script passes if at least one hotfix is installed

Massimiliano De Cò


' *********************************************************
' SCRIPT TO CHECK IF KB IS INSTALLED IN LOCAL COMPUTER
'
' script name: chk-hotfix.vbs
'
' *********************************************************
' VERSION       1.0
' LASTMODIFY    2017-05-16
' ***********************************
' AUTHOR: MASSIMILIANO DE CO' 
' ***********************************
' ARGUMENTS hotfix list space separated
' ONLY the number, no letters here!   
'
' example from elevated command prompt (the last two parameter is for Solarwinds MAX RMM)
'
' cscript chk-hotfix.vbs 4012598 4012212 4012215 4012598 4012213 4012216 4012214 4012217 4012606 4013429 4015217 4013198 -param1 -logfile 


Const RESULT_PASS = 0
Const RESULT_FAIL = 1
Const RESULT_NOT_FOUND = 2
Const RESULT_UNKNOWN = 3
Const adVarChar = 200
Const MaxCharacters = 255

Dim Result
Dim A_HotFixID, ComputerName
Dim aArgs,i,hotfixID,status

Result = RESULT_FAIL
Set aArgs = WScript.Arguments

If aArgs.Count = 0 Then
    WScript.Echo "Invalid Arguments"
    WScript.Quit ( RESULT_FAIL )
ElseIf aArgs(0) = "-logfile" Then
    WScript.Echo "Invalid Arguments"
    WScript.Quit ( RESULT_FAIL )
End If

' GET hotfix from ARGUMENT  
Redim A_HotFixID(aArgs.length-3)

for i = 0 to aArgs.length-3
        A_HotFixID(i) = aArgs(i)
    Next

' get all hotfix from wmi in localhost

        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 

        Set colItems = objWMIService.ExecQuery("Select Description, HotFixID, InstalledOn from Win32_QuickFixEngineering",,48)

        Set objDbrPatches = CreateObject("ADOR.Recordset")
        objDbrPatches.Fields.Append "Description", adVarChar, MaxCharacters
        objDbrPatches.Fields.Append "HotfixID", adVarChar, MaxCharacters
        'objDbrPatches.Fields.Append "InstallDate", adVarChar, MaxCharacters
        objDbrPatches.Open
        For Each objItem in colItems
            objDbrPatches.AddNew
            objDbrPatches("Description") = objItem.Description
            objDbrPatches("HotfixID") = objItem.HotfixID
            objDbrPatches.Update
        Next


' loop hotfix array
for each hotfixID in A_HotFixID

    objDbrPatches.movefirst

    objDbrPatches.find "HotfixID like '%" & hotfixID & "%'"

    If objDbrPatches.EOF then 
        wscript.Echo "The hotfix with number " & HotFixID & " is NOT installed." 
    Else
        wscript.Echo "The hotfix with number " & HotFixID & " IS installed."
        result = RESULT_PASS
    end if 

next

IF (result) = 0 then 
    WScript.echo "The script result is: PASS" 
else 
    WScript.echo "The script result is: FAIL" 
end if 


WScript.Quit(Result)

' ************************ 

private Function CheckParticularHotfix(strPuter, strHotfixID) 
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
    ' Version 1.0 
    ' Checks if a particular hotfix is installed or not.  
    ' This function has these 3 return options: 
    ' TRUE, FALSE, <error description>  
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
    'On error resume next 

    if err.number <> 0 Then    'if an error occurs 
        CheckParticularHotfix = "Unable to get WMI hotfix info" 
    else 'Error number 0 meaning no error occured  
        tal = colQuickFixes.count 
        if tal > 0 then 
            CheckParticularHotfix = True    'HF installed 
        else  
            CheckParticularHotfix = False    'HF not installed 
        end If 
    end if 
    Set colQuickFixes = Nothing 

    Err.Clear 
    On Error GoTo 0 
end function 
created 9 days ago
dcmax
 1 1 2

► Have questions?

► Something not working?

► Suggestions?

Post your questions on the meta site, where we discuss everything related to FixIT Scripts

visit meta now»