Hello all,
I am writing a script to detect a SQL installation. The script is designed run every time a user logs into the domain, to populate an email with the computer name, the version of SQL installed (if any) and email it to our IT team. The difficulty I am having is excluding our Developers AD group from the entire process. I have written a script that excludes by computer name, but I don't want to have to update the script whenever a Developer gets a new computer.
I think that all I need is a snippet that will check to see if a computer is in the Developers Group and if it is, do Then do nothing.
'On error resume next
' Set Local Computer
strComputer = "."
' Get computer name
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
strComputerName = wshNetwork.ComputerName
' If computer name = EXCLUSION logic via AD Developer Group
' This is the old method.
If wshNetwork.Computername = "Computer Name" Then
' do nothing
Else
'Check for MSSQL Service
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
sonate}!\\
" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = 'MSSQLServer'")
If colServices.Count > 0 Then
For Each objService in colServices
' SQL Server Name | Server Name\Instance Name
strDBServerName = "." ' Local Server
Set objSQLServer = CreateObject("SQLDMO.SQLSe
rver")
objSQLServer.LoginSecure = True
objSQLServer.Connect strDBServerName
' Define Email variables for yes
strFrom = "NoWhere@Nowhere.com"
'strTo = "mlptechnical@us.pwc.com"
strTo = "Admin@nowhere.com"
strSub = "SQL Server Installed Version Information for - " & strComputerName
strBody = "SQL Server is installed on - " & strComputerName
strBody = "SQL Major Version: " & objSQLServer.VersionMajor
strBody = "SQL Minor Version: " & objSQLServer.VersionMinor
strBody = "SQL Version String: " & objSQLServer.VersionString
strSMTP = "OurSmTp Server"
'send email
set objEmail = CreateObject("CDO.Message"
)
objEmail.From = strFrom
objEmail.To = strTo
objEmail.Subject = strSub
objEmail.Textbody = strBody
objEmail.Configuration.Fie
lds.Item("
http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fie
lds.Item("
http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
objEmail.Configuration.Fie
lds.Update
objEmail.Send
Next
End If
End If
ASKER