forked from ktaranov/sqlserver-kit
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathPowerSavingCheck.sql
51 lines (43 loc) · 934 Bytes
/
PowerSavingCheck.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Author: bornsql
Original link: https://github.com/bornsql/scripts/blob/master/power_saving_check.sql
Desctiption: Create power saving check
*/
DECLARE @isCmdShellEnabled BIT;
DECLARE @isShowAdvanced BIT;
SELECT
@isCmdShellEnabled = CAST(value AS BIT)
FROM
sys.configurations
WHERE
name = 'xp_cmdshell';
SELECT
@isShowAdvanced = CAST(value AS BIT)
FROM
sys.configurations
WHERE
name = 'show advanced options';
IF (@isShowAdvanced = 0)
BEGIN
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
END;
IF (@isCmdShellEnabled = 0)
BEGIN
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
END;
--Run xp_cmdshell to get power settings
EXEC xp_cmdshell 'powercfg /list';
--Turn off 'xp_cmdshell'
IF (@isCmdShellEnabled = 0)
BEGIN
EXEC sp_configure 'xp_cmdshell', 0;
RECONFIGURE;
END;
--Turn off 'show advanced options'
IF (@isShowAdvanced = 0)
BEGIN
EXEC sp_configure 'show advanced options', 0;
RECONFIGURE;
END;