199199 ,@SkipMSDB bit = 0
200200 ,@SkipModel bit = 0
201201 ,@SkipTempDB bit = 0
202- ,@SkipValidateLogins bit = 0 ;
202+ ,@SkipValidateLogins bit = 0
203+ /* Variables for check 211: */
204+ ,@powerScheme varchar (36 )
205+ ,@cpu_speed_mhz int
206+ ,@cpu_speed_ghz decimal (18 ,2 );
203207
204208 DECLARE
205209 @db_perms table
274278 SET @SkipTrace = 1 ;
275279 END ; /* We need this permission to execute trace stuff, apparently*/
276280
277- IF NOT EXISTS
278- (
279- SELECT
280- 1 / 0
281- FROM fn_my_permissions(N ' xp_regread' , N ' OBJECT' ) AS fmp
282- WHERE fmp .permission_name = N ' EXECUTE'
283- )
284- BEGIN
285- SET @SkipXPRegRead = 1 ;
286- END ; /* Need execute on xp_regread*/
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 @powersaveSetting 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*/
287312
288313 IF NOT EXISTS
289314 (
@@ -9134,30 +9159,6 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91349159
91359160 IF @Debug IN (1 , 2 ) RAISERROR (' Running CheckId [%d].' , 0 , 1 , 211 ) WITH NOWAIT ;
91369161
9137- DECLARE @outval VARCHAR (36 );
9138- /* Get power plan if set by group policy [Git Hub Issue #1620] */
9139- EXEC master .sys .xp_regread @rootkey = ' HKEY_LOCAL_MACHINE' ,
9140- @key = ' SOFTWARE\Policies\Microsoft\Power\PowerSettings' ,
9141- @value_name = ' ActivePowerScheme' ,
9142- @value = @outval OUTPUT ,
9143- @no_output = ' no_output' ;
9144-
9145- IF @outval IS NULL /* If power plan was not set by group policy, get local value [Git Hub Issue #1620]*/
9146- EXEC master .sys .xp_regread @rootkey = ' HKEY_LOCAL_MACHINE' ,
9147- @key = ' SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes' ,
9148- @value_name = ' ActivePowerScheme' ,
9149- @value = @outval OUTPUT ;
9150-
9151- DECLARE @cpu_speed_mhz int ,
9152- @cpu_speed_ghz decimal (18 ,2 );
9153-
9154- EXEC master .sys .xp_regread @rootkey = ' HKEY_LOCAL_MACHINE' ,
9155- @key = ' HARDWARE\DESCRIPTION\System\CentralProcessor\0' ,
9156- @value_name = ' ~MHz' ,
9157- @value = @cpu_speed_mhz OUTPUT ;
9158-
9159- SELECT @cpu_speed_ghz = CAST (CAST (@cpu_speed_mhz AS DECIMAL ) / 1000 AS DECIMAL (18 ,2 ));
9160-
91619162 INSERT INTO #BlitzResults
91629163 ( CheckID ,
91639164 Priority ,
@@ -9174,7 +9175,7 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91749175 ' Your server has '
91759176 + CAST (@cpu_speed_ghz as VARCHAR (4 ))
91769177 + ' GHz CPUs, and is in '
9177- + CASE @outval
9178+ + CASE @powerScheme
91789179 WHEN ' a1841308-3541-4fab-bc81-f71556f20b4a'
91799180 THEN ' power saving mode -- are you sure this is a production SQL Server?'
91809181 WHEN ' 381b4222-f694-41f0-9685-ff5bb260df2e'
0 commit comments