Skip to content

Commit 589c28f

Browse files
author
Ajay Dwivedi
committed
Updated Queries
1 parent f5ed28b commit 589c28f

File tree

8 files changed

+125
-4
lines changed

8 files changed

+125
-4
lines changed
-3.5 KB
Binary file not shown.

BlitzQueries/BlitzQueries.ssmssqlproj

+6
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@
175175
<AssociatedConnUserName />
176176
<FullPath>SQL Server 2017 Diagnostic Information Queries.sql</FullPath>
177177
</FileNode>
178+
<FileNode Name="SQLQuery1.sql">
179+
<AssociatedConnectionMoniker />
180+
<AssociatedConnSrvName />
181+
<AssociatedConnUserName />
182+
<FullPath>SQLQuery1.sql</FullPath>
183+
</FileNode>
178184
<FileNode Name="Very-Large-Databases-Optimization.sql">
179185
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
180186
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
File renamed without changes.

Experiments/Experiments.ssmssqlproj

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
<AssociatedConnUserName />
5656
<FullPath>InsertDummyData.sql</FullPath>
5757
</FileNode>
58+
<FileNode Name="Message.sql">
59+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
60+
<AssociatedConnSrvName>LOCALHOST</AssociatedConnSrvName>
61+
<AssociatedConnUserName />
62+
<FullPath>Message.sql</FullPath>
63+
</FileNode>
5864
<FileNode Name="whats-new-in-sql-server-2019.sql">
5965
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
6066
<AssociatedConnSrvName>LOCALHOST</AssociatedConnSrvName>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
$agNode = 'sqlag'
2+
3+
$tsql_CreateFunc = @"
4+
IF OBJECT_ID('dbo.fn_GetHexaDecimal') IS NULL
5+
EXEC('CREATE FUNCTION dbo.fn_GetHexaDecimal () RETURNS int AS BEGIN RETURN (SELECT 1) END;');
6+
"@;
7+
$tsql_AlterFunc = @"
8+
ALTER FUNCTION dbo.fn_GetHexaDecimal (@binvalue varbinary(256))
9+
RETURNS varchar (514)
10+
AS
11+
BEGIN
12+
DECLARE @hexvalue varchar (514)
13+
DECLARE @charvalue varchar (514)
14+
DECLARE @i int
15+
DECLARE @length int
16+
DECLARE @hexstring char(16)
17+
SELECT @charvalue = '0x'
18+
SELECT @i = 1
19+
SELECT @length = DATALENGTH (@binvalue)
20+
SELECT @hexstring = '0123456789ABCDEF'
21+
WHILE (@i <= @length)
22+
BEGIN
23+
DECLARE @tempint int
24+
DECLARE @firstint int
25+
DECLARE @secondint int
26+
SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
27+
SELECT @firstint = FLOOR(@tempint/16)
28+
SELECT @secondint = @tempint - (@firstint*16)
29+
SELECT @charvalue = @charvalue +
30+
SUBSTRING(@hexstring, @firstint+1, 1) +
31+
SUBSTRING(@hexstring, @secondint+1, 1)
32+
SELECT @i = @i + 1
33+
END
34+
35+
SET @hexvalue = @charvalue;
36+
RETURN @hexvalue;
37+
END
38+
"@;
39+
40+
$tsql_GetLogins = @"
41+
SELECT p.name, p.type, dbo.fn_GetHexaDecimal(p.sid) as sid
42+
FROM master.sys.server_principals p
43+
WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa';
44+
"@;
45+
46+
Invoke-Sqlcmd -ServerInstance $agNode -Database tempdb -Query $tsql_CreateFunc | Out-Null;
47+
Invoke-Sqlcmd -ServerInstance $agNode -Database tempdb -Query $tsql_AlterFunc | Out-Null;
48+
$logins = Invoke-Sqlcmd -ServerInstance $agNode -Database tempdb -Query $tsql_GetLogins;
49+
$logins | ogv

PermissionIssues/Get-Login-Sid.sql

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use tempdb
2+
go
3+
4+
IF OBJECT_ID('dbo.fn_GetHexaDecimal') IS NULL
5+
EXEC('CREATE FUNCTION dbo.fn_GetHexaDecimal () RETURNS int AS BEGIN RETURN (SELECT 1) END;');
6+
GO
7+
ALTER FUNCTION dbo.fn_GetHexaDecimal (@binvalue varbinary(256))
8+
RETURNS varchar (514)
9+
AS
10+
BEGIN
11+
DECLARE @hexvalue varchar (514)
12+
DECLARE @charvalue varchar (514)
13+
DECLARE @i int
14+
DECLARE @length int
15+
DECLARE @hexstring char(16)
16+
SELECT @charvalue = '0x'
17+
SELECT @i = 1
18+
SELECT @length = DATALENGTH (@binvalue)
19+
SELECT @hexstring = '0123456789ABCDEF'
20+
WHILE (@i <= @length)
21+
BEGIN
22+
DECLARE @tempint int
23+
DECLARE @firstint int
24+
DECLARE @secondint int
25+
SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
26+
SELECT @firstint = FLOOR(@tempint/16)
27+
SELECT @secondint = @tempint - (@firstint*16)
28+
SELECT @charvalue = @charvalue +
29+
SUBSTRING(@hexstring, @firstint+1, 1) +
30+
SUBSTRING(@hexstring, @secondint+1, 1)
31+
SELECT @i = @i + 1
32+
END
33+
34+
SET @hexvalue = @charvalue;
35+
RETURN @hexvalue;
36+
END
37+
GO
38+
39+
SELECT p.name, p.type, p.sid, dbo.fn_GetHexaDecimal(p.sid) as sid_hex
40+
FROM master.sys.server_principals p
41+
WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa';

PermissionIssues/PermissionIssues.ssmssqlproj

+16-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@
4949
<AssociatedConnUserName />
5050
<FullPath>Database-Permissions-(Direct+Indirect).sql</FullPath>
5151
</FileNode>
52+
<FileNode Name="Get-Login-Sid.sql">
53+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:localhost:True</AssociatedConnectionMoniker>
54+
<AssociatedConnSrvName>localhost</AssociatedConnSrvName>
55+
<AssociatedConnUserName />
56+
<FullPath>Get-Login-Sid.sql</FullPath>
57+
</FileNode>
58+
<FileNode Name="Get-Login-Sid-Powershell.sql">
59+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:localhost:True</AssociatedConnectionMoniker>
60+
<AssociatedConnSrvName>localhost</AssociatedConnSrvName>
61+
<AssociatedConnUserName />
62+
<FullPath>Get-Login-Sid-Powershell.sql</FullPath>
63+
</FileNode>
5264
<FileNode Name="GetPermissions.sql">
5365
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:localhost:True</AssociatedConnectionMoniker>
5466
<AssociatedConnSrvName>localhost</AssociatedConnSrvName>
@@ -67,11 +79,11 @@
6779
<AssociatedConnUserName />
6880
<FullPath>Install Powershell ISE.sql</FullPath>
6981
</FileNode>
70-
<FileNode Name="SQLQuery1.sql">
71-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPCNPDB1:True</AssociatedConnectionMoniker>
72-
<AssociatedConnSrvName>TUL1CIPCNPDB1</AssociatedConnSrvName>
82+
<FileNode Name="Take-Ownership-of-Files-Folders.sql">
83+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:localhost:True</AssociatedConnectionMoniker>
84+
<AssociatedConnSrvName>localhost</AssociatedConnSrvName>
7385
<AssociatedConnUserName />
74-
<FullPath>SQLQuery1.sql</FullPath>
86+
<FullPath>Take-Ownership-of-Files-Folders.sql</FullPath>
7587
</FileNode>
7688
</Items>
7789
</LogicalFolder>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
takeown /f “c:\program files\microsoft sql server” /a /r
2+
3+
(/a is for ‘administratrators’; /r is for recurse)
4+
5+
icacls "microsoft sql server" /t /grant administrators:f
6+
7+
(/t is for recurse; :f is for full control)

0 commit comments

Comments
 (0)