Avatar of mlptechnical
mlptechnical

asked on 

VBScript to exclude via Active Directory Group

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=impersonate}!\\" & 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.SQLServer")
            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.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
            objEmail.Configuration.Fields.Update
            objEmail.Send

            Next

      End If
End If  
VB Script

Avatar of undefined
Last Comment
RobSampson
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mlptechnical
mlptechnical

ASKER

thank you very much!  wonnderful.
Avatar of RobSampson
RobSampson
Flag of Australia image

No problem. Thanks for the grade.

Regards,

Rob.
VB Script
VB Script

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

39K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo