0

I'm writing a script which will automate the extraction of data from .blg Perfmon logs.

I've worked out the primary Import-Counter commands I will need to use to get the data out, but am trying to parametrise this so that I can do it for each machine in the log file (without having to open the log up in Perfmon, which can take 15 minutes or sometimes more, and is the reason I'm writing this script), and find out what each hostname is.

The script I have does the job, but it still takes a minute to return the data I want, and I wondered if there was a simpler way to do this, as I'm not too familiar with Powershell?

Here's what I have:

$counters = Import-Counter -Path $log_path$logfile -ListSet * | Select-Object paths -ExpandProperty paths

$svrs = @()

# for each line in the list of counters, extract the name of the server and add it to the array
foreach ($line in $counters) {
    $svrs += $line.split("\")[2]
}

# remove duplicates and sort the list of servers
$sorted_svrs = $svrs | sort -unique

foreach ($svr in $sorted_svrs) {
    Write-Host $svr
}

I'm just printing the names for the moment, but they'll go into an array in the proper script, and then I'll run my Import-Counter block with each of these hosts parametrised in.

Just wondered if there was a better way of doing this?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Jagot
  • 13
  • 1
  • 3

1 Answers1

0
$sorted_svrs=Import-Counter "$log_path$logfile" -Counter "\\*\physicaldisk(_total)\% disk time" | %{$_.countersamples.path.split("\")[2]} | sort -Unique
Jackie
  • 2,476
  • 17
  • 20