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
266270
267271 IF ISNULL (@SkipXPRegRead, 0 ) != 1 /* If @SkipXPRegRead hasn't been set to 1 by the caller*/
268272 BEGIN
269- IF OBJECT_ID (N ' tempdb..#XpRegReadTest' ) IS NOT NULL
270- EXEC sp_executesql N ' DROP TABLE #XpRegReadTest;' ;
271-
272- CREATE TABLE #XpRegReadTest
273- (
274- [Value] varchar (20 )
275- ,[Data] int
276- );
277-
278273 BEGIN TRY
279- INSERT INTO #XpRegReadTest
280- (
281- [Value]
282- ,[Data]
283- )
284- EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
285- @key = N ' ' ,
286- @value_name = N ' ' ;
287-
288- SET @SkipXPRegRead = 0 ; /* We can execute xp_regread*/
274+ /* Get power plan if set by group policy [Git Hub Issue #1620] */
275+ EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
276+ @key = N ' SOFTWARE\Policies\Microsoft\Power\PowerSettings' ,
277+ @value_name = N ' ActivePowerScheme' ,
278+ @value = @powerScheme OUTPUT ,
279+ @no_output = N ' no_output' ;
280+
281+ IF @powersaveSetting IS NULL /* If power plan was not set by group policy, get local value [Git Hub Issue #1620]*/
282+ EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
283+ @key = N ' SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes' ,
284+ @value_name = N ' ActivePowerScheme' ,
285+ @value = @powerScheme OUTPUT ;
286+
287+ /* Get the cpu speed*/
288+ EXEC xp_regread @rootkey = N ' HKEY_LOCAL_MACHINE' ,
289+ @key = N ' HARDWARE\DESCRIPTION\System\CentralProcessor\0' ,
290+ @value_name = N ' ~MHz' ,
291+ @value = @cpu_speed_mhz OUTPUT ;
292+
293+ /* Convert the Megahertz to Gigaherth */
294+ SET @cpu_speed_ghz = CAST (CAST (@cpu_speed_mhz AS decimal ) / 1000 AS decimal (18 ,2 ));
295+
296+ SET @SkipXPRegRead = 0 ; /* We could execute xp_regread*/
289297 END TRY
290298 BEGIN CATCH
291299 SET @SkipXPRegRead = 1 ; /* We have don't have execute rights or xp_regread throws an error so skip it*/
292300 END CATCH ;
293-
294- IF OBJECT_ID (N ' tempdb..#XpRegReadTest' ) IS NOT NULL
295- EXEC sp_executesql N ' DROP TABLE #XpRegReadTest;' ;
296301 END ; /* Need execute on xp_regread*/
297302
298303 IF NOT EXISTS
@@ -9103,30 +9108,6 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91039108
91049109 IF @Debug IN (1 , 2 ) RAISERROR (' Running CheckId [%d].' , 0 , 1 , 211 ) WITH NOWAIT ;
91059110
9106- DECLARE @outval VARCHAR (36 );
9107- /* Get power plan if set by group policy [Git Hub Issue #1620] */
9108- EXEC master .sys .xp_regread @rootkey = ' HKEY_LOCAL_MACHINE' ,
9109- @key = ' SOFTWARE\Policies\Microsoft\Power\PowerSettings' ,
9110- @value_name = ' ActivePowerScheme' ,
9111- @value = @outval OUTPUT ,
9112- @no_output = ' no_output' ;
9113-
9114- IF @outval IS NULL /* If power plan was not set by group policy, get local value [Git Hub Issue #1620]*/
9115- EXEC master .sys .xp_regread @rootkey = ' HKEY_LOCAL_MACHINE' ,
9116- @key = ' SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes' ,
9117- @value_name = ' ActivePowerScheme' ,
9118- @value = @outval OUTPUT ;
9119-
9120- DECLARE @cpu_speed_mhz int ,
9121- @cpu_speed_ghz decimal (18 ,2 );
9122-
9123- EXEC master .sys .xp_regread @rootkey = ' HKEY_LOCAL_MACHINE' ,
9124- @key = ' HARDWARE\DESCRIPTION\System\CentralProcessor\0' ,
9125- @value_name = ' ~MHz' ,
9126- @value = @cpu_speed_mhz OUTPUT ;
9127-
9128- SELECT @cpu_speed_ghz = CAST (CAST (@cpu_speed_mhz AS DECIMAL ) / 1000 AS DECIMAL (18 ,2 ));
9129-
91309111 INSERT INTO #BlitzResults
91319112 ( CheckID ,
91329113 Priority ,
@@ -9143,7 +9124,7 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
91439124 ' Your server has '
91449125 + CAST (@cpu_speed_ghz as VARCHAR (4 ))
91459126 + ' GHz CPUs, and is in '
9146- + CASE @outval
9127+ + CASE @powerScheme
91479128 WHEN ' a1841308-3541-4fab-bc81-f71556f20b4a'
91489129 THEN ' power saving mode -- are you sure this is a production SQL Server?'
91499130 WHEN ' 381b4222-f694-41f0-9685-ff5bb260df2e'
0 commit comments