While there are several ways to attack this problem, I put together this PowerShell script to create an import file.
Code: Select all
# Create WMI Import.ps1
# Created by Andrew Rodriguez
# Email: andrew.mywork :at: gmail :dot: com
# Version: 0.1
# Created: 08/19/2010
# Last modification: 08/19/2010
# Notes:
#
# You'll want to do the following before using:
# 1. Modify $path where you save your script
# 2. Modify $destFolder as needed
# 3. Create the "raw_counters.txt" file
# 4. Modify $counters where you saved the previously mentioned file.
# Optionally:
# 5. You may want to modify "Interval =" and "Alerts ="
# Setup default variables
# -----------------------
$path = "C:\Dev\HostMonitor\"
$destFolder = "Root\"
$crlf = "`r`n"
$server = Read-Host "Enter a server name:"
$folder = Read-Host "Enter folder name (folder must exist!):"
$file = "$path$server$(get-date -f yyyy-MM-dd-hh-mm-ss).txt"
$counters = Get-Content "C:\Dev\HostMonitor\raw_counters.txt"
foreach ($counter in $counters)
{
$counter
"Method = PerfCounter" + $crlf | Out-File $file -Append -encoding UTF8
";--" + $server + " - " + $counter + $crlf | Out-File $file -Append -encoding UTF8
"DestFolder = " +$destFolder + $folder + "\" + $crlf | Out-File $file -Append -encoding UTF8
"Title = PerfCounter: " + $counter.split("\")[-2,-1] + $crlf | Out-File $file -Append -encoding UTF8
"Comment = PerfCounter: " + $counter + $crlf | Out-File $file -Append -encoding UTF8
"RelatedURL = " + $crlf | Out-File $file -Append -encoding UTF8
"NamePattern = PerfCounter: %object%" + $crlf | Out-File $file -Append -encoding UTF8
"CmntPattern = PerfCounter: %path%" + $crlf | Out-File $file -Append -encoding UTF8
"ScheduleMode= Regular" + $crlf | Out-File $file -Append -encoding UTF8
"Schedule = 7 Days, 24 Hours" + $crlf | Out-File $file -Append -encoding UTF8
"Interval = 60" + $crlf | Out-File $file -Append -encoding UTF8
"Alerts = Testing Alert" + $crlf | Out-File $file -Append -encoding UTF8
"ReverseAlert= No" + $crlf | Out-File $file -Append -encoding UTF8
"UnknownIsBad= Yes" + $crlf | Out-File $file -Append -encoding UTF8
"WarningIsBad= Yes" + $crlf | Out-File $file -Append -encoding UTF8
"UseCommonLog= Yes" + $crlf | Out-File $file -Append -encoding UTF8
"PrivLogMode = Default" + $crlf | Out-File $file -Append -encoding UTF8
"CommLogMode = Default" + $crlf | Out-File $file -Append -encoding UTF8
";--- Test specific properties ---" + $crlf | Out-File $file -Append -encoding UTF8
"PerfCounter = \\" + $server + $counter + $crlf | Out-File $file -Append -encoding UTF8
"Condition = " + $crlf | Out-File $file -Append -encoding UTF8
"Value = " + $crlf | Out-File $file -Append -encoding UTF8
"DisplayMode = AsIs" + $crlf | Out-File $file -Append -encoding UTF8
"" + $crlf | Out-File $file -Append -encoding UTF8
"" + $crlf | Out-File $file -Append -encoding UTF8
}
Sample file for raw_counters.txt
Code: Select all
\Cache\MDL Read Hits %
\Memory\% Committed Bytes In Use
\Memory\Available MBytes
\Memory\Page Reads/sec
\Memory\Pages/sec
\Memory\Pool Nonpaged Bytes
\Network Interface(*)\Bytes Received/sec
\Network Interface(*)\Bytes Sent/sec
\Network Interface(*)\Packets Outbound Discarded
\Network Interface(*)\Packets Received Discarded
\PhysicalDisk(*)\Avg. Disk Queue Length
\PhysicalDisk(*)\Avg. Disk sec/Transfer
\PhysicalDisk(*)\% Disk Time
\Processor(_Total)\% Interrupt Time
\Processor(_Total)\% Privileged Time
\Processor(_Total)\% Processor Time
\Processor(_Total)\% User Time
\System\Context Switches/sec
\System\Processor Queue Length
\System\System Up Time
\System\Threads