SharePoint Server MVP for Another Year


I have been honourd to be SharePoint Server MVP for another year.  This will be my 6th year.  Special Thanks to Microsoft and to friends and family. 

Everything is slowly transitioning to Office365 lately but I am still involved in large On-Premises projects at HP.  I will keep sharing as much information as I have.  Best of luck to each and every one of you.  Once again huge thanks to Microsoft for recognizing the community.

Clearning up Large Lists and Recycle Bin with PowerShell


If you want to dump large lists quickly you can use batch delete script mentioend below.  Deleing items one by one in loop will take a lot of time.  Even if you delete the items they will get stuck in site collection recyle bin.  You can modify the script as needed.

Add-PSSnapin Microsoft.SharePoint.powerShell -ErrorAction SilentlyContinue 
$sitecollectionUrl = https://portal.contoso.com
$siteCollection = New-Object Microsoft.SharePoint.SPSite($sitecollectionUrl)
$web = $siteCollection.OpenWeb('Web') 

$list = $web.Lists["Logging List"] 

write-host("Logging List has : $list.ItemCount Items.") -ForegroundColor Yellow
write-host("Recyle Bin has : $siteCollection.RecycleBin.Count Items.") -ForegroundColor Yellow 

$itemCount = 0;
$listId = $list.ID;
[System.Text.StringBuilder]$batchXml = New-Object "System.Text.StringBuilder";
$batchXml.Append("<?xml version=`"1.0`" encoding=`"UTF-8`"?><Batch>");
$command = [System.String]::Format( "<Method><SetList>{0}</SetList><SetVar Name=`"ID`">{1}</SetVar><SetVar Name=`"Cmd`">Delete</SetVar></Method>", $listId, "{0}" ); 

$listItems = $list.Items
foreach ($item in $listItems)
{
    if($item -ne $null){$batchXml.Append([System.String]::Format($command, $item.ID.ToString())) | Out-Null;$itemCount++;}
} 

$batchXml.Append("</Batch>");
$itemCount; 

$web.ProcessBatchData($batchXml.ToString()) | Out-Null;Write-Host("Starting to Clear Site Collection Recyle Bin: $siteCollection.RecycleBin.Count") -ForegroundColor Yellow 
$siteCollection.RecycleBin.DeleteAll();
Write-Host("Cleared Log List and Site Collection Recyle Bin.")
$web.Dispose()
$siteCollection.Dispose()
 

Changing Site Collection Quota for Personal Sites


During migration of personal Sites from SharePoint 2010 to SharePoint 2013 I saw an issue where most of Personal Sites quota is not assigned properly.  The reason could be the my site databases are not upgraded successfully.  I tried some basic PowerShell script to change the personal site quota but got the following error.

image

I even tried with Server OM with PowerShell but result was same.  So for now I will say just fix the database upgrade issue.

Get List of Personal Sites and Quota

Start-SPAssignment -Global
$PersonalSites = @();
$MySites = get-spwebapplication https://mysites.contoso.com/
foreach($Site in $MySites.Sites)
{
    if($Site.Url.Contains("personal")) #Ignore MySite Host
    {
        $Site = New-Object PSObject
        Add-Member -input $Site noteproperty 'Url' $Site.Url
        Add-Member -input $Site noteproperty 'Quota' $Site.Quota
        $PersonalSites += $Site
    }
}
Stop-SPAssignment -Global
$PersonalSites | Out-File C:\MySiteQuota.txt 

Change the Quota for Personal Sites

Start-SPAssignment -Global
$TemplateName = "Personal Site"
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates[$TemplateName] 

$MySites = Get-SPWebApplication https://mysites.contoso.com/ | Get-SPSite -Limit ALL | 
  Where-Object {$_.ServerRelativeUrl.Contains("/personal/")} |
  ForEach-Object { $_.Quota = $quotaTemplate }
Stop-SPAssignment -Global

Controlling Maximum Site Count for Content Databases


Here is a quick and directy Powershell script to get and change the Maximum Site Count for the Content databases in SharePoint.  We had a large farm with hundred of databases so I used the following script to set the Maximum Site Count equal to current Sites in the database and Warning to less than 1.  You can change it based on the logic of your choice.

Get the List of Databases in a text file

$Databases = @();
foreach($aDB in Get-SPContentDatabase)
{
    $DB = New-Object PSObject
    Add-Member -input $DB noteproperty 'Name' $aDB.Name
    Add-Member -input $DB noteproperty 'Maximum' $aDB.MaximumSiteCount
    Add-Member -input $DB noteproperty 'Warning' $aDB.WarningSiteCount
    Add-Member -input $DB noteproperty 'Current' $aDB.Sites.Count
    $Databases += $DB
    Write-Host $aDB.Name + " " + $aDB.MaximumSiteCount + " " + $aDB.WarningSiteCount 
}
$Databases  | Out-File C:\DatabasesBefore.txt
#$Databases  | Out-GridView

Change the values

foreach($aDB in Get-SPContentDatabase)
{
    if(!$aDB.Name.Contains("MySite"))
    {
        Write-Host $aDB.Name
        $MaxSiteCount = $aDB.MaximumSiteCount
        $WarningCount = $aDB.WarningSiteCount
        $CurrentCount = $aDB.Sites.Count 

        Write-Host "$aDB.Name $MaxSiteCount $WarningCount $CurrentCount" -ForegroundColor Yellow
            $aDB.MaximumSiteCount = $CurrentCount
            $aDB.WarningSiteCount = $CurrentCount - 1
            $aDB.Update()
            Write-Host "$aDB.Name $aDB.MaximumSiteCount $WarningCount $CurrentCount" -ForegroundColor Green 

    }
}

Note: The script is excluding mysites databases and will fail for content DB which has no site collection so please add the logic based on your environment

You can re-run the first script if you want to verify the change but Central Administration –> Manage Content Database will show you the updates straight away.

Disable Open in Client Feature on All Site Collection in a Web Application


Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
$Connect = Get-SPWebApplication https://portal.contoso.com

$Sites = $Connect.Sites
ForEach ($Site in $Sites)
{ 
    Write-Host "Open Documents in Client Applications Feature for: $Site" -foregroundcolor Yellow;
    Disable-SPFeature -id 8a4b8de2-6fd8-41e9-923c-c7c3c00f8295 -URL $Site.Url -Force -Confirm:$false
    Write-Host "Open Documents in Client Applications Feature for: $Site is now Disabled" -foregroundcolor Green;
    $Site.Dispose()
}