Monday, October 8, 2018

Powershell One Liners: Get current cpu utilization on all your SQL Servers

# Assuming you have list of servers in servers.txt, each server name in its own line

$ComputerNames = get-content servers.txt


# Method 1 - Using the Get-Counter cmdlet
# Notice that here you can also easily add the interval and max sample sizes


Get-Counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 10 -MaxSamples 5 -ComputerName $ComputerNames | Export-Counter -path PercentageProcessorTime.csv -fileformat csv -force

# Method 2 - Using WMI Object
Get-WmiObject -Query "Select * from Win32_PerfFormattedData_PerfOS_Processor where name = '_Total'" -ComputerName $ComputerNames | sort PercentProcessorTime -descending | ft -Property PSComputerName, name, PercentProcessorTime -autosize







No comments:

Post a Comment

Truncating very large transaction log in full recovery mode

While I always configure transaction log backups for every database in non-simple recovery model, and to compliment it I also have monitorin...