Pages

script that has WMI connection error will skip it and move to next

strComputer = "MYcomputername"

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

objExcel.Cells(1, 1).Value = "Logon Name"

objExcel.Cells(1, 2).Value = "Full Name"

objExcel.Cells(1, 3).Value = "Description"

objExcel.Cells(1, 4).Value = "Domain"

objExcel.Cells(1, 5).Value = "Password Changeable"

objExcel.Cells(1, 6).Value = "Password Required"

objExcel.Cells(1, 7).Value = "Password Expires"

objExcel.Cells(1, 8).Value = "Account Disabled"

objExcel.Cells(1, 9).Value = "Account Locked Out"

On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If err.Number <> 0 then
       Call Wscript.echo("Error has occurred connecting to WMI on workstation: " & strComputer)
End if

Set colItems = objWMIService.ExecQuery("Select * from Win32_UserAccount")

For Each objItem in colItems

objExcel.Cells(intRow, 1).Value = objItem.Name

objExcel.Cells(intRow, 2).Value = objItem.FullName

objExcel.Cells(intRow, 3).Value = objItem.Description

objExcel.Cells(intRow, 4).Value = objItem.Domain

If objItem.PasswordChangeable = True Then

objExcel.Cells(intRow, 5).Value = "Yes"

objExcel.Cells(intRow, 5).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 5).Value = "No"

objExcel.Cells(intRow, 5).Font.ColorIndex = 3

End If

If objItem.PasswordRequired = True Then

objExcel.Cells(intRow, 6).Value = "Yes"

objExcel.Cells(intRow, 6).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 6).Value = "No"

objExcel.Cells(intRow, 6).Font.ColorIndex = 3

End If

If objItem.PasswordExpires = True Then

objExcel.Cells(intRow, 7).Value = "Yes"

objExcel.Cells(intRow, 7).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 7).Value = "No"

objExcel.Cells(intRow, 7).Font.ColorIndex = 3

End If

If objItem.Disabled = True Then

objExcel.Cells(intRow, 8).Value = "Yes"

objExcel.Cells(intRow, 8).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 8).Value = "No"

objExcel.Cells(intRow, 8).Font.ColorIndex = 3

End If

If objItem.Lockout = True Then

objExcel.Cells(intRow, 9).Value = "Yes"

objExcel.Cells(intRow, 9).Font.ColorIndex = 10

Else   

objExcel.Cells(intRow, 9).Value = "No"

objExcel.Cells(intRow, 9).Font.ColorIndex = 3

End If

intRow = intRow + 1

Next

objExcel.Range("A1:I1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

MsgBox "Done"

0 comments:

Post a Comment