USE SharePoint_Config
CREATE TABLE ##SiteAdmins (
DBName NVARCHAR(200),
SiteId UNIQUEIDENTIFIER,
SiteInfo NVARCHAR(200),
OwnerID INT,
PrimaryAdmin NVARCHAR(255),
PrimaryAdminDeleted INT,
SecondaryContactID INT,
SecondaryAdmin NVARCHAR(255),
SecondaryAdminDeleted INT,
)
DECLARE @contentDbName NVARCHAR(200);
DECLARE contentDbCursor CURSOR FOR
SELECT [Name] FROM [Objects]
WHERE Properties LIKE '<object type="Microsoft.SharePoint.Administration.SPContentDatabase, Microsoft.SharePoint%'
OPEN contentDbCursor
FETCH NEXT FROM contentDbCursor
INTO @contentDbName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @cmd AS VARCHAR(2000)
SET @cmd = 'USE [' + @contentDbName + ']
INSERT INTO ##SiteAdmins
(DBName, SiteId, SiteInfo, OwnerID, PrimaryAdmin, PrimaryAdminDeleted, SecondaryContactID, SecondaryAdmin, SecondaryAdminDeleted)
SELECT
''' + @contentDbName + ''' AS DBName,
S.Id AS SiteId,
''/'' + W.FullUrl + '' ('' + W.Title + '')'' AS SiteInfo,
S.OwnerID,
CASE
WHEN S.OwnerID IS NULL THEN ''Not specified''
ELSE ISNULL(PA.tp_Title, ''Unknown user'')
END AS PrimaryAdmin,
CASE WHEN
(S.OwnerID IS NOT NULL AND PA.tp_Title IS NULL)
OR PA.tp_Deleted = 1 THEN 1
ELSE 0
END AS PrimaryAdminDeleted,
S.SecondaryContactID,
CASE
WHEN S.SecondaryContactID IS NULL THEN ''Not specified''
ELSE ISNULL(SA.tp_Title, ''Unknown user'')
END AS SecondaryAdmin,
CASE WHEN
(S.SecondaryContactID IS NOT NULL AND SA.tp_Title IS NULL)
OR SA.tp_Deleted = 1 THEN 1
ELSE 0
END AS SecondaryAdminDeleted
FROM Sites S
LEFT JOIN UserInfo PA ON PA.tp_ID = S.OwnerID AND PA.tp_SiteID = S.Id
LEFT JOIN UserInfo SA ON SA.tp_ID = S.SecondaryContactID AND SA.tp_SiteID = S.Id
LEFT JOIN Webs W ON W.Id = S.RootWebId AND W.SiteId = S.Id'
EXECUTE(@cmd)
FETCH NEXT FROM contentDbCursor
INTO @contentDbName
END
CLOSE contentDbCursor
DEALLOCATE contentDbCursor
SELECT DBName, SiteId, SiteInfo, OwnerID, PrimaryAdmin, PrimaryAdminDeleted, SecondaryContactID, SecondaryAdmin, SecondaryAdminDeleted FROM ##SiteAdmins
DROP TABLE ##SiteAdmins
No comments:
Post a Comment