Home > Monitor CPU > Monitor CPU utilization from T-SQL & Powershell

Monitor CPU utilization from T-SQL & Powershell

This piece of code may help when you are not able to remote login to the server.

Script:

SET NOCOUNT ON

DECLARE @CPU TABLE (Output varchar(max))

DECLARE @Text varchar(20);

DECLARE @Utilization varchar(10);

insert into @CPU exec master.dbo.xp_cmdshell ‘Powershell -Command Get-WmiObject win32_processor’

delete from @CPU where output not like ‘Load%’

select @Text= ‘CPU Utilization’ ,

@Utilization=substring(output,charindex(‘ :’,output)+2, len(output)) + ‘ %’ from @CPU where Output IS NOT NULL

Print @Text + ‘ : ‘ +@Utilization

SET NOCOUNT OFF

go 10
CPU Utilization

Categories: Monitor CPU
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: