Friday, August 3, 2018

Get IIS App Pool status of specific server in a SharePoint farm

Use below one line statement to get the App pool status on specific server in a farm. $name variable contains the fully qualified domain name of the server. Below example get the details of IIS application pool named "SharePoint Web Services Root".

$name = "<insert Server FQDN>";
$aps=Invoke-Command -ComputerName $name {Import-Module WebAdministration; Get-ChildItem IIS:\AppPools | where{$_.Name -eq "SharePoint Web Services Root"}}


Find SharePoint Server Name hosting Central Admin site using powershell.

Took me sometime to figure this out. I am using two commands in a single line statement to fetch the server name which is hosting central administration website in a SharePoint farm.

Note-: Output of this will show you two servers in case you have configured central admin on two servers in a farm.


Get-SPServer |where {(Get-SPServiceInstance -Server $_.Address |Where {$_.Status -eq "online" -And $_.TypeName -eq "Central Administration"}) }


Friday, April 20, 2018

set Lock State (No Access, ready only, no additions, unlock) of all site collections in a SharePoint farm using powershell

Normally site lock functionality is available at site collection level only and not at farm level or even web application level, I came across a requirement where in I was asked to lock all site collections in farm. Since my farm has more than 20000 site collection it would have been a tedious task if I had to to it manually one by one.

-----------------------------------------------------------------------------------------------------------------------
Have created a Powershell script to set the all site collection in a farm to "NO Access" mode.

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue;
Start-SPAssignment -Global;
$webapps= Get-SPWebApplication;
$LockState= "NoAccess"; 
Write-Host "Setting all web applications to $($LockState)..." -ForegroundColor Yellow;
foreach ($webapp in $webapps)
{
$sites= Get-SPSite -WebApplication $webapp -Limit All;
$sites | ForEach-Object{
Write-Host "Setting site collection $_.Url to $($LockState)..." -ForegroundColor Yellow;
        Set-SPSiteAdministration -LockState $LockState -Identity $_.url;}
}
Stop-SPAssignment -Global;
Write-Host "Finished!" -ForegroundColor Green;

------------------------------------------------------------------------------------------------------------------------

Below are the valid values for LockState variable 

  • Unlock to unlock the site collection and make it available to users.
  • NoAdditions to prevent users from adding new content to the site collection. Updates and deletions are still allowed.
  • ReadOnly to prevent users from adding, updating, or deleting content.
  • NoAccess to prevent users from accessing the site collection and its content. Users who attempt to access the site receive an error message.

Get Site collection count in a farm

Use the below script to get count of all site collections in a farm.
$AllWA = Get-SPWebapplication;
foreach($wa in $AllWA){$WA.Sites | Measure-Object | Format-List Count};

Thursday, December 7, 2017

Fix:Failed to Sql Query data XEvent collector on SQL server. The error is Object reference not set to an instance of an object.

This is a common error message you will see in ULS logs. The reason for this error are the diagnostics jobs which need Serveradmin/sysadmin role to be granted to Farm admin account. it would make sense to grant farm account server admin role on sql server if we are interested to get the data which these diagnostics jobs collect. But in most of the cases I have found that we would not need these jobs nor we would like to grant farm account sysadmin role on SQL server. This issue common to both SharePoint 2010 and SharePoint 2013.

To get list of diagnostics jobs execute the below powershell command

PS C:\Windows\system32> Get-SPDiagnosticsProvider

Name                                                    Retention  MaxTotalSi Enabled   
                                                                   zeInBytes            
----                                                    ---------  ---------- -------   
job-diagnostics-blocking-query-provider                 15         6200000000 False     
job-diagnostics-sql-dmv-provider                        15         1000000... True      
job-diagnostics-uls-provider                            15         1000000... True      
job-diagnostics-performance-counter-sql-provider        15         6200000000 True      
job-diagnostics-performance-counter-wfe-provider        15         1000000... True      
job-diagnostics-event-log-provider                      15         6200000000 True      
job-diagnostics-changed-objects-provider                15         6200000000 True      
job-diagnostics-sql-blocking-report-provider            15         6200000000 True      
Search Health Monitoring - Trace Events                 15         1290000... True      
job-diagnostics-io-intensive-query-provider             15         1000000... True      
job-diagnostics-change-types-provider                   15         6200000000 True      
job-diagnostics-sql-memory-provider                     15         1000000... False     
job-diagnostics-sprequestusage-provider                 15         6200000000 True      
job-diagnostics-sql-deadlock-provider                   15         6200000000 True    
In order to get rid of the error message from ULS logs, either we need to grant farm account sysadmin role on SQL server or disable the diagnostics jobs.

Use the below script to disable the diagnostic jobs.

providers = Get-SPDiagnosticsProvider
foreach($provider in $providers)
{
   if(($provider.Name -eq "job-diagnostics-sql-blocking-report-provider") 
-or ($provider.Name -eq "job-diagnostics-io-intensive-query-provider") 
-or ($provider.Name -eq "job-diagnostics-sql-deadlock-provider"))
    {
        $provider.IsDisabled = $true;
        $provider.Update();
    }
}
Now execute the Get-SPDiagnosticsProvider command to make sure that enabled attribute is set to false.

Tuesday, July 4, 2017

Change Top Bar text of Central Administration site.

Use the below powershell commands to change the top bar text of central admin site. I use this text to concur the farm environment, like test, QA or Prod

$ca= Get-SPWebApplication -IncludeCentralAdministration | ?{$_.IsAdministrationWebApplication -eq $true};

$ca.SuiteBarBrandingElementHtml = “<div class=’ms-core-brandingText’>Central Administration- QA</div>“;

$ca.Update();



Sunday, October 16, 2016

Install SharePoint 2013 with Product key that has number of allowed installation exceeded--SharePoint 2013-AutoSPInstaller product bug(not recommended)

Note-: Please try this at your own risk. this is no means to promote piracy. I hope Microsoft fixes this bug with future patches/installation media.

Recently I had a situation where in customer had already initiated purchase of SharePoint license key as the number of installations had exceeded the number of permitted installation with the existing product key. if we try to use this key in SharePoint installation wizard, it will promptly give us an error message stating the key is invalid. since number of valid/allowed installations is already over.

I normally use AutoSPInstallater for SharePoint installation as I prefer having meaningful database names and also having one single script to install and provision sharePoint services.

So here come the bug part. I used this license key in AutoSPinstaller and SharePoint does not complains about it and proceeds with installation and provisioning of service application.

No issues detected while running sharepoint. After few days we got a new valid product key and we replaced it in farm.

Always please use genuine products as product developers deserve to be paid for hard work which has gone into making these softwares.

This article is just to highlight the product bug which I discovered in SharePoint 2013 and I hope MS will improve SharePoint by fixing this.