hannable80
Technical User
Can't get the computer name to output from this script. I will only bring the domain controler can anyone see my issue.
OPEN EXCEL
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
' Format the cell A1 and add the text: Service
objExcel.Cells(1, 1).Value = "Service"
objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 1).Interior.ColorIndex = 43
objExcel.Cells(1, 1).Font.ColorIndex = 2
' Format the cell A1 and add the text: Status
objExcel.Cells(1, 2).Value = "Status"
objExcel.Cells(1, 2).Font.Bold = TRUE
objExcel.Cells(1, 2).Interior.ColorIndex = 50
objExcel.Cells(1, 2).Font.ColorIndex = 2
' Format the cell A1 and add the text: Status
objExcel.Cells(1, 3).Value = "Status"
objExcel.Cells(1, 3).Font.Bold = TRUE
objExcel.Cells(1, 3).Interior.ColorIndex = 49
objExcel.Cells(1, 3).Font.ColorIndex = 2
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://DC=XX, dc=XXX, DC=XXX' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
' ` services on this computer
strComputer = objRecordSet.Fields("Name").Value
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * From Win32_Service")
' Write each service to Excel, starting in A2
Do Until objRecordSet.EOF
x = 1
For Each objService in colServices
x = x + 1
objExcel.Cells(x, 1) = objService.Name
objExcel.Cells(x, 2) = objService.State
objExcel.Cells(x, 3) = strComputer
if objService.State = "Stopped" then
objExcel.Cells(x, 2).Font.ColorIndex = 3
end if
Next
' Autofit
objExcel.Columns("A:A").EntireColumn.AutoFit
loop
OPEN EXCEL
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
' Format the cell A1 and add the text: Service
objExcel.Cells(1, 1).Value = "Service"
objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 1).Interior.ColorIndex = 43
objExcel.Cells(1, 1).Font.ColorIndex = 2
' Format the cell A1 and add the text: Status
objExcel.Cells(1, 2).Value = "Status"
objExcel.Cells(1, 2).Font.Bold = TRUE
objExcel.Cells(1, 2).Interior.ColorIndex = 50
objExcel.Cells(1, 2).Font.ColorIndex = 2
' Format the cell A1 and add the text: Status
objExcel.Cells(1, 3).Value = "Status"
objExcel.Cells(1, 3).Font.Bold = TRUE
objExcel.Cells(1, 3).Interior.ColorIndex = 49
objExcel.Cells(1, 3).Font.ColorIndex = 2
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://DC=XX, dc=XXX, DC=XXX' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
' ` services on this computer
strComputer = objRecordSet.Fields("Name").Value
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * From Win32_Service")
' Write each service to Excel, starting in A2
Do Until objRecordSet.EOF
x = 1
For Each objService in colServices
x = x + 1
objExcel.Cells(x, 1) = objService.Name
objExcel.Cells(x, 2) = objService.State
objExcel.Cells(x, 3) = strComputer
if objService.State = "Stopped" then
objExcel.Cells(x, 2).Font.ColorIndex = 3
end if
Next
' Autofit
objExcel.Columns("A:A").EntireColumn.AutoFit
loop