Performance Counter / Logman.exe

Good Morning, Good Afternoon, and Good Evening,

At the moment, I have a script, which I found on the web. I did not right this hence why I am adding the link to give credit to the creator of the script.

http://www.jonathanmedd.net/2010/11/managing-perfmon-data-collector-sets-with-powershell.html

Basically, I just changed the original path of the first line to reflect my environment. I created the two text files; one, which contains a list of performance counters, and two, which contains a list of servers.

With regards to the script, it works as expected as it creates a performance counter on each server. The script however does not create correct counters

This is an example of the counter that it is creating. 

"\\urt-s28-sc\\\urt-s28-scP\\urt-s28-scr\\urt-s28-sco\\urt-s28-scc\\urt-s28-sce\\urt-s28-scs\\urt-s28-scs\\urt-s28-sco\\urt-s28-scr\\urt-s28-sc(\\urt-s28-sc*\\urt-s28-sc)\\urt-s28-sc\\\urt-s28-sc%\\urt-s28-sc \\urt-s28-scP\\urt-s28-scr\\urt-s28-sco\\urt-s28-sc"

Another admin created a typeperf  performance counter, and in properties they got this, which is correct.

"\Processor(*)\% processor Time


I am not getting what typeperf is doing  could someone please take a look at this code, and maybe direct me in a way for me to change the code. I actually have a deadline for this one so any help is welcomed.

This is the code. 

$pwd = "C:\Users\jmateo\Desktop\TestProjects"
$counters = @(gc $pwd\perfmon_counters.txt) # List of counters one per line
$servers = @(gc $pwd\perfmon_list.txt) # List of remote computers one per line
$frequence = "00:00:30" #hh:mm:ss
$logtype = "tsv" # possibles: bin,bincirc,csv,tsv
$max_duration = "168:00:00" # 7 days
$max_size = "50" # megabytes
$l = $servers.length
$i = 0
foreach ($server in $servers)
{
$counters | % {$_ -replace "", "\\$server"} | sc $pwd\$server.txt
Write-Progress -Activity "Setting up Collections...." -Status "Collection: $i of $l" -PercentComplete (100*$i/$l)
$strCMD1 = 'C:\Windows\System32\logman.exe create counter perf_$server -s $server -si $frequence -cf $pwd\$server.txt -f $logtype -v mmddhhmm -o C:\PerfLogs\log_$server -rf $max_duration -max $max_size -u adminusername adminpassword'
$i++
Invoke-Expression $strCMD1
Start-Sleep -Milliseconds 100
$startprocess = Invoke-WmiMethod -ComputerName $server -Class Win32_Process -Name Create -ArgumentList "logman.exe start perf_$server"
ri $pwd\$server.txt

September 4th, 2015 10:52am

Hello JeffDPG,

Thanks for the post. However, I'm a bit confused about your purpose. Do you want to create a performance counter on the server or you just want a performance report with some specific criterion (such as CPU useage/memory useage) of a server?

Best Regards,

Elaine 

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 3:56am

Hello,

I want to create a performance counter through powershell, but when I try to do it, it creates it, but does not create data. I have a separate files with the metrics, but for some reason when you go into properties to see what  metrics the counter is looking at for the server I got the following properties 

"\\urt-s28-sc\\\urt-s28-scP\\urt-s28-scr\\urt-s28-sco\\urt-s28-scc\\urt-s28-sce\\urt-s28-scs\\urt-s28-scs\\urt-s28-sco\\urt-s28-scr\\urt-s28-sc(\\urt-s28-sc*\\urt-s28-sc)\\urt-s28-sc\\\urt-s28-sc%\\urt-s28-sc \\urt-s28-scP\\urt-s28-scr\\urt-s28-sco\\urt-s28-sc"

in other performance counter the 

the properties look like this 

\Processor(*)\% processor Time

if I put take this line of code out 

% {$_ -replace "", "\\$server"}

the properties in the counter change to this 

\Processor(*)\% processor Time

, but it does no collect data. I think the problem exist in that line of code. 

Everything makes sense in the script I just don't know if I am missing something here.

Thanks,

September 7th, 2015 8:12am

What is this line intended to do?

% {$_ -replace "", \\$server}

You cannot use this line:

$pwd = "C:\Users\jmateo\Desktop\TestProjects"

$pwd is an internal variable.

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 8:25am

Here is a less hard to read version.  I also fixed a number of issues:

$folder='C:\Users\jmateo\Desktop\TestProjects'

$counters=Get-Content "$folder\perfmon_counters.txt" # List of counters one per line
$servers=Get-Content "$folder\perfmon_list.txt" # List of remote computers one per line

$frequence='00:00:30' #hh:mm:ss
$logtype='tsv' # possibles: bin,bincirc,csv,tsv
$max_duration='168:00:00' # 7 days
$max_size='50' # megabytes

foreach ($server in $servers){
	$counters | % {$_ -replace "", "\\$server"} | Set-Content "$folder\server.txt"
	C:\Windows\System32\logman.exe create counter perf_$server -s $server -si $frequence -cf $folder\$server.txt -f $logtype -v mmddhhmm -o C:\PerfLogs\log_$server -rf $max_duration -max $max_size -u adminusername adminpassword
	Invoke-WmiMethod -ComputerName $server -Class Win32_Process -Name Create -ArgumentList "logman.exe start perf_$server"
}
Without knowing what is in your files any further help is not possible.
September 7th, 2015 8:42am

I got the script to work by removing 

% {$_ -replace "", \\$server}

I believe this is trying to remove my path from the text file and use use the server names, which I get from the text file.

I am going to try and use the updated versions. I will post back, but removing this 

$counters | % {$_ -replace "", "\\$server"}

seemed to have fix the problem.

Thanks You,

Free Windows Admin Tool Kit Click here and download it now
September 8th, 2015 10:08am

I got the script to work by removing 

% {$_ -replace "", \\$server}

I believe this is trying to remove my path from the text file and use use the server names, which I get from the text file.

I am going to try and use the updated versions. I will post back, but removing this 

$counters | % {$_ -replace "", "\\$server"}

seemed to have fix the problem.

Thanks You,

September 8th, 2015 2:07pm

I appreciate your help, but did this not work. Also, the two text file are simply a list of host, and performance counters to import to perf mon. 
Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 8:59am

What is in the text files. Post a sample of both.

You are clearly having a problem reading the text correctly.  We start by looking at the files.

September 9th, 2015 9:53am

I think this is what you are trying to do:

set-Location C:\Users\jmateo\Desktop\TestProjects
$servers=Get-Content perfmon_list.txt
foreach($server in $servers){
	$arglist=@(
	     'create counter perf_list',
	     "-s $server",
	     '-si 00:00:30', 
	     '-cf counters.txt',
	     '-f tsv',
	     '-v mmddhhmm',
	     '-o C:\PerfLogs\log_$server',
	     '-rf 168:00:00',
	     '-max 50',
	     '-u adminusername adminpassword'
	)
	Start-Process -FilePath logman.exe -ArgumentList $arglist
	logman.exe start perf_list -s $server
}

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 10:10am

The text files contains 1 server name. Eventually, it will have more servers

server1

server 2

the second file has different counter 

\memory bytes

ect

I got this to work already.  I am thinking of posting again. regarding the second part of this but, so far so goo. 

September 9th, 2015 10:11am

The counters.txt file does not need the server name in the counter name.  Just use full counter names.

The easiest way to create counters is to use the GUI then save the counter-set to a file.  You only need the server name when you are defining the counters remotely.

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 10:15am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics