Windows Server 2003
1832979 Members
3403 Online
110048 Solutions
New Discussion

Command or Scripts needed

 
cool...
Frequent Advisor

Command or Scripts needed

I want to find CPU,Disk,Memory usage in servers in daily basis and redirect that output to an xls/csv file .Can you please give me the command to find these utilization or script to find the utilization and redirect that output to excel sheet.
5 REPLIES 5
Edgar Zapata
Esteemed Contributor

Re: Command or Scripts needed

You can do this through System Monitor.
Start - run - perfmon.msc
counter logs - New Log Settings -
Add Counters (Pick the objects or counters you want to monitor).
At the Log Files tab, pick Text File (Comma delimited)
Add any settings you may need and you're ready to go.

Hope it helps.
Edgar Zapata
Esteemed Contributor

Re: Command or Scripts needed

Hi Suresh,

Since you need to do this in a number of servers.
Once you're done setting this up thecounter log at one single server, then you can just Save Settings as an either .htm or .html file.
Then, you can place the (htm/html) file at a network share available to other servers and import the file so the local server can get all the same settings from there. Just make sure you modify the server name at the .htm/html file before you actually start the counter log.

You can even dump the output to a .blg file so you can additionally view counter usage charts.

Hope it helps.
Edgar.
cool...
Frequent Advisor

Re: Command or Scripts needed

Thanks all for your help ,I have got a script in vbs format which gave all the required outputs
vijayvz
New Member

Re: Command or Scripts needed

Could you please provide the script. I'm also looking for that & working hard to getting the desire output.....
cool...
Frequent Advisor

Re: Command or Scripts needed

Option Explicit

Dim oWsh, oWshSysEnv, objFSO, objWMIService
Dim oDrives, oDrive, objOutFile, colItems, objItem
Dim strLineDate, strLineTime, strLineProcessorTime, strLineDriveSpace, strLinePercentCommittedBytesInUse

Set oWsh = WScript.CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")

strLineDate = Date()
strLineTime = Time()

'Gets PROCESSOR Usage
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems
strLineProcessorTime = strLineProcessorTime & " " & objItem.PercentProcessorTime
Next

'Gets MEMORY Usage
Set colItems = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_PerfFormattedData_PerfOS_Memory ")
For Each objItem In colItems
strLinePercentCommittedBytesInUse = strLinePercentCommittedBytesInUse & " " & objItem.PercentCommittedBytesInUse
Next
'Gets FREE SPACE Report
Set oDrives = objFSO.Drives
For Each oDrive In oDrives
Select Case oDrive.DriveType
Case 2 'Fixed Drives
strLineDriveSpace = strLineDriveSpace & " " & oDrive.DriveLetter & "\: " & Round(oDrive.FreeSpace / (1024 * 1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace / oDrive.TotalSize), 2) & " %) "
End Select
Next

'Output to text
Set objOutFile = objFSO.OpenTextFile("C:\Healthcheck\healthcheck.csv", 2, True)
objOutFile.WriteLine "Date ," & strLineDate & ", Time ," & strLineTime
objOutFile.WriteLine "Host Name ," & oWshSysEnv("COMPUTERNAME")
objOutFile.WriteLine "-------------------------------------------------------"
objOutFile.WriteLine "Processor Usage (%)," & strLineProcessorTime
objOutFile.WriteLine "Memory Usage (%)," & strLinePercentCommittedBytesInUse
objOutFile.WriteLine "Drive Free Space ," & strLineDriveSpace
objOutFile.WriteLine "**********************************************************"
'WScript.Echo "DONE"
WScript.Quit