Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2c94752

Browse files
authored
Update SSDB.non-service_accounts.sql
1 parent 31ca183 commit 2c94752

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

‎SSDB.non-service_accounts.sql‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ USE [$(_database)];
1212
GO
1313

1414
:setvar login_name "" -- to search for an individual account enter it here e.g. "Domain\UserName"
15-
15+
:setvar ssrs_service_account "Domain\ssrs_service_account"
1616

1717
SET XACT_ABORT ON
1818
BEGIN TRANSACTION;
@@ -39,7 +39,7 @@ PRINT 'check databases owners ... ';
3939
SELECT
4040
[Server_Name] = @@SERVERNAME
4141
, [Database_Name] = db.[name]
42-
, [Login_Name] = sl.[Name]
42+
, [Database_Owner] = sl.[Name]
4343
, [CommandToRun] = (CASE WHEN db.[is_read_only] = 1 THEN '-- Remove ReadOnly State' WHEN db.[state_desc] = 'ONLINE' THEN 'ALTER AUTHORIZATION on DATABASE::[' + db.[name] + '] to [sa];' ELSE '-- Turn On ' END)
4444
--, [Database_ID] = db.[database_id]
4545
--, [Current_State] = db.[state_desc]
@@ -100,6 +100,7 @@ PRINT 'check databases users ... ';
100100
AND dbu1.[User_Name] = dbu2.[User_Name]
101101
FOR XML PATH('')
102102
), 1, 1, '')
103+
, [CommandToRun] = 'USE [' + [Database_Name] + ']; DROP USER [' + [User_Name] + '];'
103104
--, [Login_Type]
104105
FROM
105106
@dbs_users AS dbu1
@@ -143,23 +144,32 @@ PRINT '=====================================================================';
143144
PRINT 'check report subscriptions ... ';
144145

145146
IF DB_ID('ReportServer') IS NOT NULL
147+
WITH
148+
service_account
149+
AS
150+
(
151+
SELECT [service_account_id] = [UserID], [UserName] FROM [ReportServer].[dbo].[Users] WHERE [UserName] = N'$(ssrs_service_account)'
152+
)
146153
SELECT DISTINCT
147154
[Server_Name] = @@SERVERNAME
148155
, [Report_Name] = rp.[Name]
149156
, [Subscription_Owner] = ou.[UserName]
150157
, [Subscription_Owner_ID] = ou.[UserID]
158+
, [CommandToRun] = 'UPDATE [ReportServer].[dbo].[Subscriptions] SET [OwnerID] = ''' + CAST(sa.[service_account_id] AS VARCHAR(MAX)) + ''' WHERE [OwnerID] = ''' + CAST(ou.[UserID] AS VARCHAR(MAX)) + ''''
151159
--, sb.[Report_OID]
152160
FROM
153161
[ReportServer].[dbo].[Subscriptions] AS sb
154-
INNER JOIN [ReportServer].[dbo].[Catalog] AS rp ON rp.[ItemID] = sb.[Report_OID]
155162
INNER JOIN [ReportServer].[dbo].[Users] AS ou ON ou.[UserID] = sb.[OwnerID]
163+
INNER JOIN [ReportServer].[dbo].[Catalog] AS rp ON rp.[ItemID] = sb.[Report_OID]
164+
, service_account AS sa
156165
WHERE
157166
1=1
158167
AND ou.[UserName] NOT IN(SELECT [Login_Name] COLLATE Latin1_General_CI_AS FROM #service_accounts)
159168
AND (ou.[UserName] = N'$(login_name)' OR N'$(login_name)' = N'')
160169

170+
161171
PRINT '******* ROLLBACK TRANSACTION ******* ';
162172
ROLLBACK TRANSACTION;
163173

164174
--PRINT '******* COMMIT TRANSACTION ******* ';
165-
--COMMIT TRANSACTION;
175+
--COMMIT TRANSACTION;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /