Created
December 13, 2017 14:27
-
-
Save gioxx/e40bd57cab33d536aaa4150fe803c87d to your computer and use it in GitHub Desktop.
COMPATIBILE CON KACE 8 (e superiore) - Un VBScript da eseguire in fase di avvio PC (o equivalente) per verificare che il client Kace sia correttamente installato e che l'inventario non sia più vecchio di 10 giorni. Ho scritto un articolo ad-hoc sul blog, vedi https://wp.me/pdQ5q-8T9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Verifica esistenza servizio QUEST Kace (KONEA) e ultimo inventario | |
' ----------------------------------------------------------------------------------------------------------- | |
' Author: GSolone | |
' Version: 0.3 | |
' Last modified: 13-12-2017 | |
' 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 | |
' ------------------------------------------------------------------------------------------------------------ | |
' UPDATES: | |
' 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), quella dei dati è sotto %ProgramData%\Quest. 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%") | |
' ===== QUIT DALLO SCRIPT SE LO SCRIPT VIENE AVVIATO SU DETERMINATE MACCHINE ======================================================== | |
Dim exclusions | |
exclusions = Array( "WIN7TEST", _ | |
"WIN10TEST") | |
For j=Lbound(exclusions) to Ubound(exclusions) | |
If InStr(strComputerName, exclusions(j))> 0 Then | |
'MsgBox("Debug: found " & strComputerName & " at index " & j) | |
WScript.Quit | |
End If | |
Next | |
' ===== 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 | |
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 = "tuonome@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>" | |
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 connesso (se rilevato): <strong>" & objNetwork.UserName & "</strong></li>" &_ | |
"<li>DN utente connesso (se rilevato): <strong>" & objSysInfo.UserName & "</strong></li>" | |
objMessage.Subject = "KACE Agent non aggiornato o non connesso su " & strComputerName | |
objMessage.From = "Alert Kace <kacealert@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 If | |
End If | |
Next | |
Set oFSO = Nothing | |
Set oFolder = Nothing | |
Set oFileCollection = Nothing | |
Set oFile = Nothing | |
Else | |
Destination = "tuonome@contoso.com" | |
DestinationCC = "" | |
DestinationBCC = "" | |
MailBody = "KACE Agent <strong>non installato</strong>, installare quanto prima.<br /><br />" &_ | |
"<li>Workstation: <strong>" & strComputerName & "</strong></li>" | |
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 connesso (se rilevato): <strong>" & objNetwork.UserName & "</strong></li>" &_ | |
"<li>DN utente connesso (se rilevato): <strong>" & objSysInfo.UserName & "</strong></li>" | |
objMessage.Subject = "KACE Agent non installato " & strComputerName | |
objMessage.From = "Alert Kace <kacealert@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 If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment