Facebook
From Denim Hummingbird, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 78
  1. -- SQL Diagnostic Manager v10.5.1.15  -- Copyright (c) IDERA, Inc. 2003-2020    
  2. set
  3.    transaction isolation level read uncommitted
  4.    set
  5.       lock_timeout 20000
  6.       set
  7.          implicit_transactions off if @@trancount > 0 commit transaction
  8.          set
  9.             language us_english
  10.             set
  11.                cursor_close_on_commit off
  12.                set
  13.                   query_governor_cost_limit 0
  14.                   set
  15.                      numeric_roundabort off
  16.                      select
  17.                         name,
  18.                         description,
  19.                         minimum,
  20.                         maximum,
  21.                         config_value = value,
  22.                         run_value = value_in_use,
  23.                         restart_required =
  24.                         case
  25.                            when
  26.                               is_dynamic = 1
  27.                            then
  28.                               0
  29.                            else
  30.                               1
  31.                         end
  32. , configuration_id
  33.                      from
  34.                         sys.configurations
  35.                         declare @outputTable table (Name varchar(64), Value varchar(32));
  36. declare @tempversion table (i int, Name nvarchar(100), Internal_Value bigint, Character_Value nvarchar(100));
  37. -- Minimum support for Azure  
  38. begin
  39.    try
  40.    insert into
  41.       @tempversion execute xp_msver 'WindowsVersion';
  42. end
  43. try
  44. begin
  45.    catch print ERROR_MESSAGE()
  46. end
  47. catch
  48. insert into
  49.    @outputTable(Name, Value)
  50.    select
  51.       'WindowsVersion',
  52.       Character_Value
  53.    from
  54.       @tempversion;
  55. insert into
  56.    @outputTable(Name, Value)
  57.    select
  58.       'MinutesRunning',
  59.       datediff(mi, create_date, getdate())
  60.    from
  61.       sys.databases
  62.    where
  63.       name = 'tempdb';
  64. insert into
  65.    @outputTable(Name, Value)
  66.    select
  67.       'EncryptedConnections',
  68.       count(*)
  69.    from
  70.       sys.dm_exec_connections
  71.    where
  72.       encrypt_option = 'TRUE';
  73. insert into
  74.    @outputTable(Name, Value)
  75.    select
  76.       'ServerProcessID',
  77.       convert(varchar, serverproperty('ProcessID'));
  78. insert into
  79.    @outputTable(Name, Value)
  80.    select
  81.       'TempDbRecoveryModel',
  82.       convert(varchar, DATABASEPROPERTYEX('tempdb', 'RECOVERY'));
  83. insert into
  84.    @outputTable(Name, Value)
  85.    select
  86.       'Edition',
  87.       convert(varchar, SERVERPROPERTY('Edition'));
  88. -- Minimum support for Azure  
  89. begin
  90.    try
  91.    insert into
  92.       @outputTable(Name, Value)
  93.       select
  94.          'PhysicalMemory',
  95.          (
  96.             physical_memory_kb * 1024
  97.          )
  98.       from
  99.          sys.dm_os_sys_info;
  100. end
  101. try
  102. begin
  103.    catch print ERROR_MESSAGE()
  104. end
  105. catch
  106. insert into
  107.    @outputTable(Name, Value)
  108.    SELECT
  109.       'ProductVersion',
  110.       CAST(SERVERPROPERTY('productversion') AS varchar(32));
  111. -- Check SeManageVolumePrivilege  if 1 = (select cast(value_in_use as int) from sys.configurations where configuration_id = 16390) -- xp_cmdshell must be enabled   and 1 = IS_SRVROLEMEMBER('sysadmin')
  112. -- must be in sysadmin role or a proxy account is used to run commands  
  113. begin
  114.    declare @xp__cmdshell_output table(Output VARCHAR(8000))
  115.    BEGIN
  116.       TRY               --insert into @xp__cmdshell_output exec ('xp__cmdshell ''whoami''');    
  117.       insert into
  118.          @outputTable(Name, Value)
  119.          select
  120.             top 1 'SQLServerServiceAccount',
  121.             rtrim(left([Output], 40))
  122.          from
  123.             @xp__cmdshell_output
  124.          where
  125.             [Output] is not null
  126.    END
  127.    TRY
  128.    BEGIN
  129.       CATCH
  130.    END
  131.    CATCH
  132.    BEGIN
  133.       TRY
  134.       delete
  135.       from
  136.          @xp__cmdshell_output                   --insert into @xp__cmdshell_output exec ('xp__cmdshell ''whoami /priv''');    
  137.          insert into
  138.             @outputTable(Name, Value)
  139.             select
  140.                'SeManageVolumePrivilege',
  141.                ltrim(right([Output], 8))
  142.             from
  143.                @xp__cmdshell_output
  144.             where
  145.                [Output] like 'SeManageVolumePrivilege %' if @@rowcount = 0
  146.                begin
  147.                   if (not exists
  148.                   (
  149.                      select
  150.                         *
  151.                      from
  152.                         @xp__cmdshell_output
  153.                      where
  154.                         [Output] like ('% is not recognized as %')
  155.                   )
  156. )
  157.                   insert into
  158.                      @outputTable(Name, Value)
  159.                   values
  160.                      (
  161.                         'SeManageVolumePrivilege',
  162.                         'Disabled'
  163.                      )
  164.                end
  165.    END
  166.    TRY
  167.    BEGIN
  168.       CATCH
  169.    END
  170.    CATCH
  171. end
  172. select
  173.    Name,
  174.    Value
  175. from
  176.    @outputTable;