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};