Post Patching report

Use the below Macro in Excel to get the System online status, uptime, system drive with the percentage.

””””””””””””’

Sub Diskspace()
Dim strstarttime
strstarttime = Now()
Call Cleardata
‘Declarations
Dim colcompsys As Object
Dim objcompputer As Object
Dim objwmi As Object
Dim strcomputer As String

For introw = 2 To ActiveSheet.Cells(65536, 1).End(xlUp).Row
strcomputer = ActiveSheet.Cells(introw, 1).Value

If ping(strcomputer) = True Then
strpingtest = “Online”
ActiveSheet.Cells(introw, 2).Value = strpingtest

On Error Resume Next
Set objwmi = GetObject(“winmgmts:\\” & strcomputer & “\root\cimv2”)

‘Uptime Query
Dim coluptime As Object
Set coluptime = objwmi.execquery(“Select lastbootuptime from Win32_Operatingsystem”)
uptimestr = “”
For Each objos In coluptime
diffmin = DateDiff(“n”, wmidatestringtodate(objos.lastbootuptime), Now)
diffdays = Fix(diffmin / (60 * 24))
diffmin = diffmin – diffdays * 24 * 60

If diffdays >= 1 Then
uptimestr = uptimestr & CStr(diffdays) & “day ”
End If
diffhours = Fix(diffmin / 60)
diffmin = diffmin – diffhours * 60

If diffhours >= 1 Then
uptimestr = uptimestr & CStr(diffhours) & “hours ”
End If

If diffmin >= 1 Then
uptimestr = uptimestr & CStr(diffmin) & “mins ”
End If

Next
ActiveSheet.Cells(introw, 3).Value = uptimestr
‘—————————————————————————
‘C drive space
Dim coldisks As Object
Dim rndfreespace
Dim rndtotalspace
Dim sysdisk
Dim percent
sysdisk = “”
Set coldisks = objwmi.execquery _
(“Select * from win32_logicaldisk where deviceid = ‘C:'”)
If Err.Number = 0 Then
For Each objdisk In coldisks
intfreespace = objdisk.freespace
inttotalspace = objdisk.Size
pctfreespace = Round(intfreespace / inttotalspace * 100, 2) & “%”

rndfreespace = Round(CDbl(objdisk.freespace) / 1073741824, 2)
rndtotalspace = Round(CDbl(objdisk.Size) / 1073741824)
sysdisk = rndfreespace & ” Gb of ” & rndtotalspace & ” Gb is free”
Next
ActiveSheet.Cells(introw, 4).Value = sysdisk
ActiveSheet.Cells(introw, 5).Value = pctfreespace
Else
ActiveSheet.Cells(introw, 4).Value = Err.Description
End If
‘—————————————————————————
If Err.Number = 0 Then
‘do nothing
Else: ActiveSheet.Cells(introw, 3).Value = “Error ” & Err.Number & “; ” & Err.Description
End If
Err.Clear
On Error GoTo 0
Else
ActiveSheet.Cells(introw, 2).Font.Color = RGB(1000, 0, 0)
ActiveSheet.Cells(introw, 2).Value = “OFFLINE”

End If

Next

strendtime = Now()
Strtimetaken = DateDiff(“s”, strstarttime, strendtime)

MsgBox “Script completed” & ” Total time ” & Strtimetaken & ” secs”

End Sub

Sub Cleardata()
Range(“B2:N2000”).Clear
End Sub

Function ping(strcomputer)
Dim objshell, boolcode
Set objshell = CreateObject(“wscript.shell”)
boolcode = objshell.Run(“ping -n 1 -w 300 ” & strcomputer, 0, True)
If boolcode = 0 Then
ping = True
Else
ping = False
End If

End Function
Function wmidatestringtodate(dtmdate)
wmidatestringtodate = CDate(Mid(dtmdate, 5, 2) & “/” & Mid(dtmdate, 7, 2) & “/” & Left(dtmdate, 4) & ” ” & Mid(dtmdate, 9, 2) & “:” & Mid(dtmdate, 11, 2) & “:” & Mid(dtmdate, 13, 2))

End Function

”””””””””””””””

source:

Script to check uptime and C Drive space on list of windows servers

 

 

Author: scomengineer

Rajesh Penukonda, am working as a Senior SCOM consultant at HCL Technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: