Using Powershell to get a group of specific perfmon counters
When I use your +=
block, I get back a $counters
that is a long concatenated string.
$counters += '\Memory\Available Bytes'
$counters += '\Paging File(*)\% Usage'
$counters += '\PhysicalDisk(*)\Disk Reads/sec'
$counters += '\PhysicalDisk(*)\Disk Writes/sec'
$counters += '\PhysicalDisk(*)\Avg. Disk sec/Read'
$counters += '\PhysicalDisk(*)\Avg. Disk sec/Write'
$counters += '\Processor(*)\% Processor Time'
$counters += '\System\Processor Queue Length'
$counters
\Memory\Available Bytes\Paging File(*)\% Usage\PhysicalDisk(*)\Disk Reads/sec\PhysicalDisk(*)\Disk Writes/sec\PhysicalDisk(*)\Avg. Disk sec/Read\PhysicalDisk(*)\Avg. Disk sec/Write\Processor(*)\% Processor Time\System\Processor Queue Length
$counters.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
That probably isn't what you want. If you make $counters
an array explicitly things work a little better.
$counters = @()
$counters += '\Memory\Available Bytes'
$counters += '\Paging File(*)\% Usage'
$counters += '\PhysicalDisk(*)\Disk Reads/sec'
$counters += '\PhysicalDisk(*)\Disk Writes/sec'
$counters += '\PhysicalDisk(*)\Avg. Disk sec/Read'
$counters += '\PhysicalDisk(*)\Avg. Disk sec/Write'
$counters += '\Processor(*)\% Processor Time'
$counters += '\System\Processor Queue Length'
$counters.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
$counters | Get-Counter