Computer Services Const ADS_SCOPE_SUBTREE = 2 Const ForAppending = 8 'We are going to write the output to a file Set objFSO = CreateObject("Scripting.FileSystemObject") Set objLogFile = objFSO.OpenTextFile("c:\Get_ServiceAccountName.csv", ForAppending, True) objLogFile.Write("System Name,Service State,Display Name,Account Name ") objLogFile.Writeline 'This is the name of the Account we are looking for strAccount = "SomeAccount" Set objRoot = Getobject("GC://rootDSE") strRootDomain = objRoot.Get("rootDomainNamingContext") Wscript.Echo strRootDomain 'Wscript.Quit(0) Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCOmmand.ActiveConnection = objConnection objCommand.CommandText = _ 'if You want to query the computers in a ChildDomain ' "Select Name, Location from 'GC://DC=MyChildDomain," & strRootDomain & "'" _ 'if You want to query the computers in a SPECIFIC OU ' "Select Name, Location from 'GC://OU=MySpecificOU," & strRootDomain & "'" _ 'This will query all the computers in the root Domain "Select Name, Location from 'GC://" & strRootDomain & "'" _ & "where objectClass='computer'" objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF ComputerName = objRecordSet.Fields("Name").Value Call DoEnum(ComputerName, strAccount) objRecordSet.MoveNext Loop objLogFile.Close objConnection.close Set objRecordSet = Nothing Set objCommand = Nothing Set objConnection = Nothing Sub DoEnum(ComputerName, strAccount) On Error Resume Next strComputer = ComputerName 'Just to show us the progress, we'll echo the computer name the script is working on right now Wscript.Echo strComputer 'Now we do the query Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service") For Each objService in colListOfServices 'If we match the account name, then we write the information tothe output file If instr(UCASE(objService.StartName), UCASE(strAccount) >0 Then Wscript.Echo objService.DisplayName & vbTab & objService.StartName objLogFile.Write(objService.SystemName) & "," objLogFile.Write(objService.State) & "," objLogFile.Write(objService.DisplayName) & "," objLogFile.Write(objService.StartName) & "," objLogFile.writeline End If Next Set objWMIService = Nothing End Sub