Skip to main content

Powershell Commands in SP2016 Part-I

With SharePPoint 2016 some new Powershell Cmdlets have arrived. I would like to share some of the new powershell cmdlets for SP2016 with a brief overview of each. Some cmdlets I will describe in this post and some cmdlets in next post.

Img Src: NEW AITP

SharePoint 2016 has introduced a new functionality for Site Template deployment called “Site Masters”. These are master Site Templates, configured by a SharePoint Administrator, that allow quick deployment of a Site Template when a new SharePoint Site is requested.

Creating new site master can be done through power shell cmdlet very easily.

Also, some cmdlets are added for controlling the services to make the administrator's job easy.

Lets have a glimpse at  some of new cmdlets:

Add-DatabaseToAvailabilityGroup 

This cmdlet adds one or more databases from a SharePoint farm into an availability group in SQL Server.

Eg. Add-DatabaseToAvailabilityGroup -AGName MyAvailabilityGroup -DatabaseName WSS_Content -FileShare \\backup\share\

Copy-SPAccessServicesDatabaseCredentials 

This cmdlet copies credentials of an application from one logical server to another. 

Eg. $appUrl = $app.Url.OriginalString
$web = Get-SPWeb $appUrl
$site = $web.Site
$serviceContext = [Microsoft.Sharepoint.SPServiceContext]::GetContext($serviceApp.ServiceApplicationProxyGroup, $site.SiteSubscription.Id);
$serverCredential = Get-CredentialFromSecretsHashWithFarmId -Hash $Secrets -Type $SqlAzureServerPasswordGridSecretType -FarmId $SourceSqlFarm
$sourceServerFQDN = $sourceDatabaseHost.Server + "." + $sourceDatabaseHost.Domain
$targetServerFQDN = $targetDatabaseHost.Server + "." + $targetDatabaseHost.Domain
Copy-SPAccessServicesDatabaseCredentials -ServiceContext $serviceContext -AppUrl $appUrl -SourceServer $sourceServerFQDN -TargetServer $targetServerFQDN -ServerCredential $serverCredential

Copy-SPSideBySideFiles

This cmdlet copies side by side files.  Now in SP2016, zero down tie in-place upgrade is available.

If you PSConfig.exe file during an upgrade and copy SideBySide files fail, you can use the Copy-SPSideBySideFiles cmdlet to copy side by side files. If you use Windows PowerShell scripts instead of PSConfig.exe to perform an upgrade, please run the Copy-SPSideBySideFiles cmdlet to copy side by side files.

Disable-SPWebTemplateForSiteMaster

This cmdlet disables the site master in the farm.

Eg. Disable-SPWebTemplateForSiteMaster -Template STS#0 -CompatibilityLevel 15

It will disable a site master in the farm.

Note: Running Enable-SPWebTemplateForSiteMaster cmdlet  will undo the above aperformed action.

Enable-SPWebTemplateForSiteMaster

This cmdlet creates a template for a site master.

Eg.Enable-SPWebTemplateForSiteMaster -Template STS#0 -CompatibilityLevel 15

It will create a site master in the database.

Note: Running Disable-SPWebTemplateForSiteMaster cmdlet will undo the above aperformed action.

Export-SPAccessServicesDatabase

This cmdlet exports the Access Database into a Bacpac package.

Eg. Export-SPAccessServicesDatabase -Databasename $db -ServerReferenceId $id

A Bacpac file is created by SQL Server during an export operation of a database. It contains all the information needed for moving/ importing the database to a new SQL Server.

Export-SPTagsAndNotesData

This cmdlet exports the SharePoint Newsfeed tags and notes.

It exports the SharePoint Newsfeed tags and notes from the SharePoint database to a .zip file.
The tags and notes are written into separate files, and then the two are compressed and added to the .zip file you specify. 

Eg. Export-SPTagsAndNotesData -Site http://site -FilePath C:\TagsAndNotes.zip

Get-AvailabilityGroupStatus

This cmdlet returns one or more objects representing the availability groups.

Eg. Get-AvailabilityGroupStatus -Identity MyAvailabilityGroup

Get-SPAppStoreWebServiceConfiguration 

This cmdlet returns properties of a SharePoint Store app.

It returns property settings (On-premises or Online) for SharePoint Store apps.

Eg. Get-SPAppStoreWebServiceConfiguratio

Get-SPConnectedServiceApplicationInformation 

This cmdlet returns the health of the service application proxy. It checks whether the proxy to a service application is in good health.

Eg. $validProxy = $false
$upaProxy = Get-SPServiceApplicationProxy | where{$_.TypeName -eq "User Profile Service Application Proxy"}
$proxyHealth = Get-SPConnectedServiceApplicationInformation -ServiceApplicationProxy $upaProxy
    if(($proxyHealth -ne $null) -and ($proxyHealth.ApplicationAddressesState -eq "UpToDate"))
     {
         $validProxy = $true
     }
     else
     {
       $validProxy = $false
     }

Get-SPInsightsConfig

This cmdlet returns the uploader.xml and Microsoft.Office.BigData.DataLoader.exe.config files from the Configuration database.

Eg. $config = Get-SPInsightsConfig
$xml = $config.UploaderXml
$config.UploaderXml = $xml
$config.Update()

Get-SPMicrofeedOptions

This cmdlet returns the feed cache settings for the current user profile application.

Eg. Get-SPMicrofeedOptions -ProfileServiceApplicationProxy c6681d53-e6c4-432f-9f31-22d3de81b00c

ProfileServiceApplicationProxy  is a required parameter that specifies the unique identifier for the proxy.

Get-SPService 

This cmdlet gets a service in the farm by supplying the name of the service.

Eg. Get-SPService -Identity “Microsoft SharePoint Server Diagnostics Service”

Get-SPSiteMaster

This cmdlet returns site master information of a content db that is supplied. Add -ContentDatabase WSS_Content to the cmdlet and the site master is returned.

Eg. Get-SPSiteMaster -ContentDatabase WSS_Content

ContentDatabase  is a required parameter which specifies the name of the database to get the list of site master information.

Information that is displayed includes:
  • ContentDatabase
  • SiteId
  • TemplateName
  • Language
  • CompatibilityLevel
  • FeaturesToActivateOnCopy
That's all for this post, stay tuned for the remaining cmdlets  which I will pen it down in my next blog post.

Till then Happy Learning Powershell...!!!

Comments