SharePoint: PowerShell sample scripts

Below are some of the Real Time Examples of how SharePoint can saved, analysed or managed with the help of PowerShell:

1. Getting the Active Directory properties of SharePoint User.

SharePoint stores the user details in the form of claim token which needs to be decoded when we are trying to pull the details of user like the Site Collection of a Site Collection Administrator or Owner.

Here is the sample script which came to the rescue , instead of writing huge lines of code in C# in Visual Studio. Get-SPUser is fantastic if the User Profile stores all the AD details.

$ownerSP=Get-SPSiteAdministration -Url "http://w15-sp"|select OwnerLoginName

$m = [Microsoft.SharePoint.Administration.Claims.ClaimProviderManager]::Local

$ownerAD=$m.DecodeClaim($ownerSP.OwnerLoginName)

Get-ADUser -Identity $ownerAD -Properties * | select department,county