locked
Problem with VBS Script Check Admin Local Group for SCCM RRS feed

  • Question

  • I Friends, i have a dude with my code, i need to compare whith the local admin group and return to me compliant or not compliance

    THANKSSS

        Dim members,administradores,administradores2,OSLanguage, HostName, c, usr,mem,sw,adm
        Set objLocator = CreateObject("WbemScripting.SWbemLocator")
        Set objService = objLocator.ConnectServer(".", "root\cimv2")
        objService.Security_.ImpersonationLevel = 3
        Set CS = objService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For Each objItem In CS
            HostName = objItem.Name
        Next
        Set SO = objService.ExecQuery("Select * from Win32_operatingsystem")
        For Each objItem In SO
            OSLanguage = objItem.OSLanguage
        Next
        If (OSLanguage = "3082") Then
            Set objGroup = GetObject("WinNT://" & HostName & "/Administradores")
            c = 0
            For Each objUser In objGroup.members
                If c = 0 Then usr = objUser.AdsPath Else usr = usr & "," & objUser.AdsPath
                c = c + 1
            Next
            members = Split(usr, ",")
                  administradores = Split("WinNT://" & HostName & "/Administrador,WinNT://ITCLICK\Administrador, WinNT://ITCLICK\Administrator, WinNT://ITCLICK\Domain Admins", ",")

           Else
            Set objGroup = GetObject("WinNT://" & HostName & "/Administrators")
            c = 0
            For Each objUser In objGroup.members
                If c = 0 Then usr = objUser.AdsPath Else usr = usr & "," & objUser.AdsPath
                c = c + 1
            Next
            members = Split(usr, ",")
               administradores = Split("WinNT://" & HostName & "/Administrador,WinNT://ITCLICK\Administrador, WinNT://ITCLICK\Administrator, WinNT://ITCLICK\Domain Admins", ",")
        End If
       
       
        For Each mem In members
        msgbox mem
            sw = False
            For Each adm In administradores

                If adm = mem Then sw = True
            Next
            If Not sw Then
                Wscript.Echo "No Compliance"
                Exit For
            End If
        Next
            If sw Then Wscript.Echo "Compliant"
           

    T
    Saturday, September 12, 2020 5:06 AM

All replies

  • What error do you get?

    What statement is failing?

    Try adding some wscript.echo statements to display the data contents of your variables to verify that they contain the data that you expect to find.   

    Saturday, September 12, 2020 4:40 PM