Greetings!
Below is a working script that will spit out the services running on a given machine into a csv file. The problem is that I need it to run on remote servers that are not part of the domain. Please help!
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objOutput = objFSO.OpenTextFile(".\services.csv", ForAppending, True)
objOutput.Write ("System Name,IP Address,Date Ran,Caption,Service Status,Startup Type,Service Name,Account Name")
objOutput.Writeline
On Error Resume Next
Set InputFile = objFSO.OpenTextFile(".\computers.ini")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
strCommand = "%comspec% /c ping -n 1 -w 100 " & strComputer & ""
Set objExecObject = objShell.Exec(strCommand)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
If Instr(strText, "Reply") > 0 Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set oServices = objWMIService.ExecQuery ("Select * from Win32_Service")
For Each objService in oServices
objOutput.Write(objService.SystemName) & ","
objOutput.Write(StrComputer) & ","
objOutput.Write(Date) & ","
objOutput.Write(objService.Caption) & ","
objOutput.Write(objService.State) & ","
objOutput.Write(objService.StartMode) & ","
objOutput.Write(objService.Name) & ","
objOutput.Write(objService.StartName) & ","
objOutput.writeline
Next
End If
Loop
Loop
objOutput.Close
Thanks!
Below is a working script that will spit out the services running on a given machine into a csv file. The problem is that I need it to run on remote servers that are not part of the domain. Please help!
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objOutput = objFSO.OpenTextFile(".\services.csv", ForAppending, True)
objOutput.Write ("System Name,IP Address,Date Ran,Caption,Service Status,Startup Type,Service Name,Account Name")
objOutput.Writeline
On Error Resume Next
Set InputFile = objFSO.OpenTextFile(".\computers.ini")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
strCommand = "%comspec% /c ping -n 1 -w 100 " & strComputer & ""
Set objExecObject = objShell.Exec(strCommand)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
If Instr(strText, "Reply") > 0 Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set oServices = objWMIService.ExecQuery ("Select * from Win32_Service")
For Each objService in oServices
objOutput.Write(objService.SystemName) & ","
objOutput.Write(StrComputer) & ","
objOutput.Write(Date) & ","
objOutput.Write(objService.Caption) & ","
objOutput.Write(objService.State) & ","
objOutput.Write(objService.StartMode) & ","
objOutput.Write(objService.Name) & ","
objOutput.Write(objService.StartName) & ","
objOutput.writeline
Next
End If
Loop
Loop
objOutput.Close
Thanks!