-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
power_saving_check.sql
53 lines (43 loc) · 1.13 KB
/
power_saving_check.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
52
53
/*
Power Saving Check
https://bornsql.ca/
Copyright (c) BornSQL.ca
Written by Randolph West, released under the MIT License
Last updated: 19 June 2020
A simple Windows Registry scan, using xp_cmdshell 'powercfg /list'.
This script respects your 'show advanced options' and 'xp_cmdshell'
settings under sp_configure, and will set them back the way it found
them.
*/
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;