Wednesday, April 6, 2016

Create Perfmon on Remote Machines


Scenario: You want to start perfmon on several remote machines.  You have a list of machines, but you don't want to remotely create and start those perfmon data collector sets.

Here is a PowerShell script that you can use to start up perfmon data collector sets on a remote machine.  It pulls the list of computers from a .csv file called "computers.csv".  Your .csv should looks something like this:



Be sure to enter "pcname" at the top of your column as the script looks at that.

$machinename = $entry.pcname

You can, of course change this.  Just make sure that whatever you put here, you also put at the top of your column in your .csv file.

Here is the rest of the powershell script (USE AT YOUR OWN RISK)

#This script will create and start long and short interval performance counters on remote machines.
#The remote machines are defined in the "computers.csv" file.
$list = Import-Csv "C:\TEMP\computers.csv"
foreach ($entry in $list)
{
try 
    {
$machinename = $entry.pcname
$RemoteComputer = "\\"+$machinename 
Logman create counter -s $RemoteComputer PerfLog-ShortInterval -o "c:\perflogs\PerfLog-ShortRemote.blg" -f bincirc -v mmddhhmm -max 500 -c "\LogicalDisk(*)\*" "\Memory\*" "\.NET CLR Memory(*)\*" "\Cache\*" "\Network Interface(*)\*" "\Netlogon(*)\*" "\Paging File(*)\*" "\PhysicalDisk(*)\*" "\Processor(*)\*" "\Processor Information(*)\*" "\Process(*)\*" "\Thread(*)\*" "\Redirector\*" "\Server\*" "\System\*" "\Server Work Queues(*)\*" "\Terminal Services\*" -si 00:00:02
Logman create counter -s $RemoteComputer PerfLog-LongInterval -o "c:\perflogs\PerfLog-LongInterval.blg" -f bincirc -v mmddhhmm -max 500 -c "\LogicalDisk(*)\*" "\Memory\*" "\.NET CLR Memory(*)\*" "\Cache\*" "\Network Interface(*)\*" "\Netlogon(*)\*" "\Paging File(*)\*" "\PhysicalDisk(*)\*" "\Processor(*)\*" "\Processor Information(*)\*" "\Process(*)\*" "\Thread(*)\*" "\Redirector\*" "\Server\*" "\System\*" "\Server Work Queues(*)\*" "\Terminal Services\*" -si 00:02:00
Logman start PerfLog-LongInterval -s $RemoteComputer
Logman start PerfLog-ShortInterval -s $RemoteComputer
    }
    catch [Exception]
    {
    Write-Host "Copy Failure " $_
 
    }
}
Always test your scripts before using them in a production environment.  This script is provided "as-is".

No comments:

Post a Comment