Un VBScript da eseguire per verificare che il client Kace sia correttamente installato e che l'inventario non sia più vecchio di 10 giorni. Segui l'articolo sul blog: https://wp.me/pdQ5q-9RO
' Verifica esistenza servizio QUEST Kace (KONEA) e ultimo inventario | |
' ----------------------------------------------------------------------------------------------------------- | |
' Author: GSolone | |
' Version: 0.5 | |
' Last modified: 22-10-2018 | |
' Credits: https://www.symantec.com/connect/downloads/vbscript-delete-old-files | |
' http://www.robvanderwoude.com/vbstech_network_ip.php | |
' http://www.robvanderwoude.com/vbstech_network_names_computer.php | |
' https://social.technet.microsoft.com/Forums/en-US/a8d29535-217e-46c0-bd94-0a203a322015/current-logged-in-user-using-vbscript?forum=ITCG | |
' https://gallery.technet.microsoft.com/scriptcenter/01fcf945-ad73-44e0-8cb5-152432bc6bcf | |
' https://rcmtech.wordpress.com/2011/04/15/vbscript-instr-with-the-and-operator/ | |
' https://stackoverflow.com/questions/11879612/qtp-checking-if-an-array-of-strings-contains-a-value | |
' https://stackoverflow.com/questions/3031497/how-to-verify-if-file-exist-with-vb-script | |
' http://www.morpheusweb.it/html/manuali/vbscript/vbscript_procedure.asp | |
' ------------------------------------------------------------------------------------------------------------ | |
' UPDATES: | |
' 0.5- rimosso controllo macchine da escludere, la GPO viene applicata solo sulle macchine dove serve far girare lo script. Corretto inoltre riferimento a utente connesso (che nel nuovo caso GPO è sempre SYSTEM), da "Utente connesso" a "Utente che ha lanciato il check". | |
' 0.4- ho aggiunto un check in più relativo all'esistenza del kinventory.db (ancora prima di verificarne l'ultima data di aggiornamento). Ho isolato l'invio mail in una funzione (MailtoKacelog) e la richiamo dove serve. | |
' 0.3- allineato con Kace 8.0.318 e bundle agenti 8.0.152, la cartella di installazione dell'agent è adesso sotto %ProgramFiles(x86)%\Quest (si abbandona la \Dell). Modifico i puntamenti. | |
' 0.2 rev1- ho aggiunto una esclusione in lista e ho splittato l'array nella modalità "1 riga, 1 esclusione" (in ordine alfabetico) | |
' 0.2- ho fatto merge di tutti gli ignore dei vari domini (un solo script, copiato ovunque), utilizzando un Array di hostname da escludere. | |
Dim oFSO, oFolder, sDirectoryPath | |
Dim oFileCollection, oFile, sDir | |
Dim iDaysOld | |
sDirectoryPath = "C:\ProgramData\Quest\Kace" | |
Set objNTInfo = CreateObject("WinNTSystemInfo") | |
Set objMessage = CreateObject("CDO.Message") | |
Set oFSO = CreateObject("Scripting.FileSystemObject") | |
Set wshShell = CreateObject("WScript.Shell") | |
Set oFolder = oFSO.GetFolder(sDirectoryPath) | |
Set oFileCollection = oFolder.Files | |
Set objNetwork = CreateObject("Wscript.Network") | |
Set objSysInfo = Createobject("ADSystemInfo") | |
iDaysOld = 10 | |
strComputerName = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") | |
' ===== FUNCTION MAILTO KACELOG GROUP =============================================================================================== | |
Function MailtoKacelog(Destination, DestinationCC, DestinationBCC, MailBody, Subject) | |
strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''" | |
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" ) | |
Set colItems = objWMIService.ExecQuery( strQuery, "WQL", 48 ) | |
For Each objItem In colItems | |
If IsArray(objItem.IPAddress) Then | |
If UBound(objItem.IPAddress) = 0 Then | |
strIP = "<li>IP macchina: <strong>" & objItem.IPAddress(0) & "</strong></li>" | |
Else | |
strIP = "<li>IP macchina: <strong>" & Join( objItem.IPAddress, ", " ) & "</strong></li>" | |
End If | |
End If | |
Next | |
MailBody = MailBody & strIP &_ | |
"<li>Utente che ha lanciato il check (se rilevato): <strong>" & objNetwork.UserName & "</strong></li>" &_ | |
"<li>DN utente connesso (se rilevato): <strong>" & objSysInfo.UserName & "</strong></li>" | |
objMessage.Subject = Subject | |
objMessage.From = "Management - Alert Kace <kacelog@contoso.com>" | |
objMessage.To = Destination | |
objMessage.Cc = DestinationCC | |
objMessage.Bcc = DestinationBCC | |
objMessage.HTMLBody = MailBody | |
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 | |
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.contoso.com" | |
objMessage.Configuration.Fields.Update | |
objMessage.Send | |
End Function | |
' ===== VERIFICA ESISTENZA SERVIZIO KONEA, QUINDI VERIFICA ULTIMO INVENTARIO ======================================================== | |
strComputer = "." | |
Set objWMIService = GetObject("winmgmts:" _ | |
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") | |
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name='konea'") | |
nItems = colRunningServices.Count | |
' If the collection count is greater than zero the service will exist. | |
If nItems > 0 Then | |
'Test esistenza %ProgramData%\Quest\Kace\kinventory.db | |
If (oFSO.FileExists(sDirectoryPath & "\kinventory.db")) Then | |
'MsgBox("Debug: kinventory.db found " & strComputerName) | |
Else | |
Destination = "kacelog@contoso.com" | |
DestinationCC = "" | |
DestinationBCC = "" | |
MailBody = "KACE Agent: kinventory.db non rilevato, verificare quanto prima da console.<br /><br />" &_ | |
"<li>Workstation: <strong>" & strComputerName & "</strong></li>" | |
Subject = "KACE Agent: kinventory.db non trovato su " & strComputerName | |
Call MailtoKacelog(Destination, DestinationCC, DestinationBCC, MailBody, Subject) | |
End If | |
For each oFile in oFileCollection | |
'DEBUG: il file cacert.pem è sempre più vecchio dei 10 giorni (su macchine già avviate da tempo), si può utilizzare per verificare che lo script lo rilevi e invii alert mail: | |
'If oFile.Name = "cacert.pem" Then | |
If oFile.Name = "kinventory.db" Then | |
If oFile.DateLastModified < (Date() - iDaysOld) Then | |
Destination = "kacelog@contoso.com" | |
DestinationCC = "" | |
DestinationBCC = "" | |
MailBody = "KACE Agent <strong>non connesso o non aggiornato</strong>, verificare quanto prima da console.<br /><br />" &_ | |
"<li>Workstation: <strong>" & strComputerName & "</strong></li>" | |
Subject = "KACE Agent non aggiornato o non connesso su " & strComputerName | |
Call MailtoKacelog(Destination, DestinationCC, DestinationBCC, MailBody, Subject) | |
End If | |
End If | |
Next | |
Set oFSO = Nothing | |
Set oFolder = Nothing | |
Set oFileCollection = Nothing | |
Set oFile = Nothing | |
Else | |
Destination = "kacelog@contoso.com" | |
DestinationCC = "" | |
DestinationBCC = "" | |
MailBody = "KACE Agent <strong>non installato</strong>, installare quanto prima.<br /><br />" &_ | |
"<li>Workstation: <strong>" & strComputerName & "</strong></li>" | |
Subject = "KACE Agent non installato " & strComputerName | |
Call MailtoKacelog(Destination, DestinationCC, DestinationBCC, MailBody, Subject) | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment