Skip to content

Instantly share code, notes, and snippets.

@gioxx
Created November 3, 2017 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gioxx/19574f2a39f7f5f106eba355da5cc8d9 to your computer and use it in GitHub Desktop.
Save gioxx/19574f2a39f7f5f106eba355da5cc8d9 to your computer and use it in GitHub Desktop.
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-8Qi
' Verifica esistenza servizio Dell Kace (KONEA) e ultimo inventario
' -----------------------------------------------------------------------------------------------------------
' Author: GSolone
' Version: 0.2 rev1
' Info: https://gioxx.org/tag/VBScript
' Last modified: 16-10-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
' ------------------------------------------------------------------------------------------------------------
Dim oFSO, oFolder, sDirectoryPath
Dim oFileCollection, oFile, sDir
Dim iDaysOld
sDirectoryPath = "C:\ProgramData\Dell\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