Thursday 10 April 2014

Changing Site Collection Primary Administrator in SharePoint Using SQL SERVER


If you  want to Change Site Collection Primary administrator Using SQL Server

update [ContentDataBaseName].[dbo].[UserInfo] set tp_Login='Domain\UserName', tp_Title='UserName' where tp_ID=UserID and tp_SiteID='SiteCollectionID'


If you  want to Change Site Collection Secondary administrator Using SQL Server

update [ContentDataBaseName].[dbo].[AllSites] set OwnerID=UserID , SecondaryContactID=UserID where id='SiteCollectionID'

Find User Information In SharePoint Content Data Base using SQL SERVER

****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 [tp_SiteID]
      ,[tp_ID]
      ,[tp_DomainGroup]
      ,[tp_SystemID]
      ,[tp_Deleted]
      ,[tp_SiteAdmin]
      ,[tp_IsActive]
      ,[tp_Login]
      ,[tp_Title]
      ,[tp_Email]
      ,[tp_Notes]
      ,[tp_Token]
      ,[tp_ExternalToken]
      ,[tp_ExternalTokenLastUpdated]
      ,[tp_Locale]
      ,[tp_CalendarType]
      ,[tp_AdjustHijriDays]
      ,[tp_TimeZone]
      ,[tp_Time24]
      ,[tp_AltCalendarType]
      ,[tp_CalendarViewOptions]
      ,[tp_WorkDays]
      ,[tp_WorkDayStartHour]
      ,[tp_WorkDayEndHour]
      ,[tp_Mobile]
      ,[tp_Flags]
  FROM [WSS_Content_2010_Solar_Test_181213].[dbo].[UserInfo]

Find SharePoint Site collection list using SharePoint Configuration Data Base Using SQL SERVER


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