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
@@ -9186,7 +9150,39 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91869150 WHERE DatabaseName IS NULL AND CheckID = 211 )
91879151 BEGIN
91889152
9153+ /* Variables for check 211: */
9154+ DECLARE
9155+ @powerScheme varchar (36 )
9156+ ,@cpu_speed_mhz int
9157+ ,@cpu_speed_ghz decimal (18 ,2 )
9158+ ,@ExecResult int ;
9159+
91899160 IF @Debug IN (1 , 2 ) RAISERROR (' Running CheckId [%d].' , 0 , 1 , 211 ) WITH NOWAIT ;
9161+ IF @sa = 0 RAISERROR (' The errors: '' xp_regread() returned error 5, '' Access is denied.'' '' can be safely ignored' , 0 , 1 ) WITH NOWAIT ;
9162+
9163+ /* Get power plan if set by group policy [Git Hub Issue #1620] */
9164+ EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
9165+ @key = N ' SOFTWARE\Policies\Microsoft\Power\PowerSettings' ,
9166+ @value_name = N ' ActivePowerScheme' ,
9167+ @value = @powerScheme OUTPUT ,
9168+ @no_output = N ' no_output' ;
9169+
9170+ IF @powerScheme IS NULL /* If power plan was not set by group policy, get local value [Git Hub Issue #1620]*/
9171+ EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
9172+ @key = N ' SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes' ,
9173+ @value_name = N ' ActivePowerScheme' ,
9174+ @value = @powerScheme OUTPUT ;
9175+
9176+ /* Get the cpu speed*/
9177+ EXEC @ExecResult = xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
9178+ @key = N ' HARDWARE\DESCRIPTION\System\CentralProcessor\0' ,
9179+ @value_name = N ' ~MHz' ,
9180+ @value = @cpu_speed_mhz OUTPUT ;
9181+
9182+ /* Convert the Megahertz to Gigahertz */
9183+ IF @ExecResult != 0 RAISERROR (' We couldn'' t retrieve the CPU speed, you will see Unknown in the results' , 0 , 1 )
9184+
9185+ SET @cpu_speed_ghz = CAST (CAST (@cpu_speed_mhz AS decimal ) / 1000 AS decimal (18 ,2 ));
91909186
91919187 INSERT INTO #BlitzResults
91929188 ( CheckID ,
@@ -9202,7 +9198,7 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
92029198 ' Power Plan' AS Finding,
92039199 ' https://www.brentozar.com/blitz/power-mode/' AS URL ,
92049200 ' Your server has '
9205- + CAST (@cpu_speed_ghz as VARCHAR (4 ) )
9201+ + ISNULL ( CAST (@cpu_speed_ghz as VARCHAR (8 )), ' Unknown ' )
92069202 + ' GHz CPUs, and is in '
92079203 + CASE @powerScheme
92089204 WHEN ' a1841308-3541-4fab-bc81-f71556f20b4a'
0 commit comments