200200 ,@SkipModel bit = 0
201201 ,@SkipTempDB bit = 0
202202 ,@SkipValidateLogins bit = 0
203- /* Variables for check 211: */
204- ,@powerScheme varchar (36 )
205- ,@cpu_speed_mhz int
206- ,@cpu_speed_ghz decimal (18 ,2 );
207203
208204 DECLARE
209205 @db_perms table
278274 SET @SkipTrace = 1 ;
279275 END ; /* We need this permission to execute trace stuff, apparently*/
280276
281- IF ISNULL (@SkipXPRegRead, 0 ) != 1 /* If @SkipXPRegRead hasn't been set to 1 by the caller*/
282- BEGIN
283- BEGIN TRY
284- /* Get power plan if set by group policy [Git Hub Issue #1620] */
285- EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
286- @key = N ' SOFTWARE\Policies\Microsoft\Power\PowerSettings' ,
287- @value_name = N ' ActivePowerScheme' ,
288- @value = @powerScheme OUTPUT ,
289- @no_output = N ' no_output' ;
290-
291- IF @powerScheme IS NULL /* If power plan was not set by group policy, get local value [Git Hub Issue #1620]*/
292- EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
293- @key = N ' SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes' ,
294- @value_name = N ' ActivePowerScheme' ,
295- @value = @powerScheme OUTPUT ;
296-
297- /* Get the cpu speed*/
298- EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
299- @key = N ' HARDWARE\DESCRIPTION\System\CentralProcessor\0' ,
300- @value_name = N ' ~MHz' ,
301- @value = @cpu_speed_mhz OUTPUT ;
302-
303- /* Convert the Megahertz to Gigahertz */
304- SET @cpu_speed_ghz = CAST (CAST (@cpu_speed_mhz AS decimal ) / 1000 AS decimal (18 ,2 ));
305-
306- SET @SkipXPRegRead = 0 ; /* We could execute xp_regread*/
307- END TRY
308- BEGIN CATCH
309- SET @SkipXPRegRead = 1 ; /* We have don't have execute rights or xp_regread throws an error so skip it*/
310- END CATCH ;
311- END ; /* Need execute on xp_regread*/
312-
313277 IF NOT EXISTS
314278 (
315279 SELECT
@@ -9167,7 +9131,39 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91679131 WHERE DatabaseName IS NULL AND CheckID = 211 )
91689132 BEGIN
91699133
9134+ /* Variables for check 211: */
9135+ DECLARE
9136+ @powerScheme varchar (36 )
9137+ ,@cpu_speed_mhz int
9138+ ,@cpu_speed_ghz decimal (18 ,2 )
9139+ ,@ExecResult int ;
9140+
91709141 IF @Debug IN (1 , 2 ) RAISERROR (' Running CheckId [%d].' , 0 , 1 , 211 ) WITH NOWAIT ;
9142+ IF @sa = 0 RAISERROR (' The errors: '' xp_regread() returned error 5, '' Access is denied.'' '' can be safely ignored' , 0 , 1 ) WITH NOWAIT ;
9143+
9144+ /* Get power plan if set by group policy [Git Hub Issue #1620] */
9145+ EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
9146+ @key = N ' SOFTWARE\Policies\Microsoft\Power\PowerSettings' ,
9147+ @value_name = N ' ActivePowerScheme' ,
9148+ @value = @powerScheme OUTPUT ,
9149+ @no_output = N ' no_output' ;
9150+
9151+ IF @powerScheme IS NULL /* If power plan was not set by group policy, get local value [Git Hub Issue #1620]*/
9152+ EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
9153+ @key = N ' SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes' ,
9154+ @value_name = N ' ActivePowerScheme' ,
9155+ @value = @powerScheme OUTPUT ;
9156+
9157+ /* Get the cpu speed*/
9158+ EXEC @ExecResult = xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
9159+ @key = N ' HARDWARE\DESCRIPTION\System\CentralProcessor\0' ,
9160+ @value_name = N ' ~MHz' ,
9161+ @value = @cpu_speed_mhz OUTPUT ;
9162+
9163+ /* Convert the Megahertz to Gigahertz */
9164+ IF @ExecResult != 0 RAISERROR (' We couldn'' t the CPU speed, you will see Unknown in the results' , 0 , 1 )
9165+
9166+ SET @cpu_speed_ghz = CAST (CAST (@cpu_speed_mhz AS decimal ) / 1000 AS decimal (18 ,2 ));
91719167
91729168 INSERT INTO #BlitzResults
91739169 ( CheckID ,
@@ -9183,7 +9179,7 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91839179 ' Power Plan' AS Finding,
91849180 ' https://www.brentozar.com/blitz/power-mode/' AS URL ,
91859181 ' Your server has '
9186- + CAST (@cpu_speed_ghz as VARCHAR (4 ) )
9182+ + ISNULL ( CAST (@cpu_speed_ghz as VARCHAR (8 )), ' Unknown ' )
91879183 + ' GHz CPUs, and is in '
91889184 + CASE @powerScheme
91899185 WHEN ' a1841308-3541-4fab-bc81-f71556f20b4a'
0 commit comments