About Me

SharePoint Architect with over 17 years of IT Experience in various roles as SharePoint Architect, Administrator, Technical Architect, IT Analyst, Application Developer, CRM Consultant, BI Developer, Microsoft Solution Architect in Client/Server, Web and Enterprise CRM Applications in E-Commerce, Financial, Healthcare, Insurance, Telecom, Outsourcing and Technology Services.
MCITP (Pro): Microsoft Certified IT Professional: SharePoint 2010 Administrator.
MCTS: Microsoft Certified Technology Specialist, SharePoint 2010 Configuration.

Thursday, August 7, 2014

Assign New Database Id




stsadm -o addcontentdb -url http://portal -databasename WSS_Content_DB -assignnewdatabaseid

content database shows zero site collections in it You probably need to update the site map in the config db.


$db = get-spcontentdatabase -Identity [insert guid of cdb here]
$db.RefreshSitesInConfigurationDatabase()


$app = get-spwebapplication identity url of the problem web app
$app.contentdatabses.count


$db = get-spwebapplication identity url of the webapplication that had the null entry 
$db.contentdatabses.delete(“guidOfProblemDb”)
$db = Get-SPDatabase -Identity "guidOfProblemDb"
$db.Delete()

Find WebPart usage in SharePoint Content Database

#Write Header to CSV File
$outputfile = "C:\PowerShellScripts\FindWebPart\VeritableFindWebPart.csv"

"Page URL,  Web Part Name" | out-file $outputfile

#Get all Webs
$WebApp = Get-SPWebApplication "http://dev.spsiteurl.com"
foreach($site in $WebApp.Sites)
{
#Iterate through webs
foreach ($web in $site.AllWebs)
{
#Get All Pages from site's Root into $AllPages Array
$AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})

#Search All Folders for Pages
foreach ($folder in $web.Folders)
    {
       #Add the pages to $AllPages Array
       $AllPages += @($folder.Files | Where-Object {$_.Name -match ".aspx"})
    }
 
 #Iterate through all pages
 foreach($Page in $AllPages)
  {
     $webPartManager = $web.GetLimitedWebPartManager($Page.ServerRelativeUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
   
     # Array to Hold Closed Web Parts
                foreach ($webPart in $webPartManager.WebParts | Where-Object {$_ -like "*ViewClaims*"})
                {
                 $result = "$($web.site.Url)$($Page.ServerRelativeUrl), $($webpart.Title)"
                 Write-Host "Web Part Found at: "$result
                 $result | Out-File $outputfile  -Append
                }
         }
    }
 }

#Read more: http://www.sharepointdiary.com/2014/03/sharepoint-web-part-usage-report.html#ixzz313fhYrwl

Missing Features in SharePoint


Helpful Scripts, Queries to troubleshoot missing features in SharePoint Content.

select fullurl, description 
from WSS_Content_Sites1.dbo.Features f
join WSS_Content_clientsites.dbo.Webs w on f.WebId=w.Id
where FeatureId = '75a0fea7-c54f-46b9-86b1-2e103a8fedba'

fullurl                 description
sites/Intranet/policy                                                                                                     
sites/Intranet/IT                                                                                                           
(2 row(s) affected)

Find WebPart usage for WebPartTypeID
SELECT 
Webs.FullUrl As SiteUrl, 
Webs.Title 'Document/List Library Title', 
DirName + '/' + LeafName AS 'Document Name'
from AllDocs with (nolock)
INNER JOIN Webs On AllDocs.WebId = Webs.Id
INNER JOIN Sites ON Webs.SiteId = SItes.Id
inner join WebParts 
on AllDocs.Id = WebParts.tp_PageUrlID 
where 
WebParts.tp_WebPartTypeID = '8be2f2c4-7478-16ab-c942-bd8a1b0d7cef'

Find Feature details based on Setup Path
SELECT * FROM [WSS_Content_DB].[dbo].[AllDocs] a
with (nolock) WHERE a.[SetupPath] LIKE '%TSATypes%'



SQL Server scripts for routine database operations


Modify only Database name
ALTER DATABASE DB_OldName MODIFY NAME = DB_NewName
GO

Alter Logical Names (only)
ALTER DATABASE [DB_Name] MODIFY FILE (NAME=N'DB_DataFileNameOld', NEWNAME= N’DB_DataFileNameNew')
GO
ALTER DATABASE [DB_Name] MODIFY FILE (NAME=N'DB_LogFileNameOld_log', NEWNAME= N’DB_LogFileNameNew_log')
GO

Restore Database backup with new Database file names.
RESTORE DATABASE [DatabaseName] FROM DISK = 'P:\DatabasBackup.bak'
WITH
MOVE 'DB_DataLogicalName' TO 'P:\MSSQL.SHAREPOINT\Data\DatabaseName_NewName.mdb',
MOVE 'DB_LogLogicalName_Log' TO 'P:\MSSQL.SHAREPOINT\Log\DatabaseName_NewName_Log.ldf',

RECOVERY, REPLACE, STATS = 10;

Testing a Login to Database in PowerShell
When you run the following script you shouldn't get any error and script terminates gracefully.

$dataSource = "SQLDEV\SharePoint"
$user = "SharePointUser"$pwd = "Password"$database = "DatabaseName"$connectionString = "Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;"$connection = New-Object System.Data.SqlClient.SqlConnection$connection.ConnectionString = $connectionString$connection.Open()

Note: If you get an error as "A network-related error or instance-specific error occurred..." then you are connecting to an incorrect SQL Server instance or the ports may be blocking your communication.

     Run query after opening connection in above script.
     $query = "SELECT * FROM aspnet_Users"
     $command = $connection.CreateCommand()
     $command.CommandText = $query
     $result = $command.ExecuteReader()


Fix Database login during Database migrations
When you migrate a database with an existing login which you want to map your database user to, you could run the following. First parameter of ‘SharePointDBUser′ is the user in the database, the second one is login existing in SQL Server securities to be mapped to.
EXEC sp_change_users_login 'update_one','SharePointDBUser','SharePointDBUser'