Tuesday, November 11, 2014

Adding PowerShell Snap-in Sharepoint 2013


PowerShell Snap-in Sharepoint 2013



Windows PowerShell is a command-line shell and scripting language that provides an administrator full access to applicable application programming interfaces (APIs). Administrators can interact directly with SharePoint 2013 to manipulate web applications, site collections, sites, lists and much more. In addition, an administrator can script cmdlets (pronounced “command-lets”).


You can manage most aspects of SharePoint 2013 in the SharePoint Management Shell. You can create new site collections, web applications, user accounts, service applications, proxies, and more.


Commands that you type in the SharePoint Management Shell return SharePoint objects that are based on the Microsoft .NET Framework.

You can apply these objects as input to subsequent commands or store the objects in local variables for later use.


To execute any powershell script, adding PowerShell Snap-in is required.
Here is the script to add it!


try

Write-Host "Adding PowerShell Snap-in" -ForegroundColor Green

# Try to get the PowerShell Snappin. If not, then adding the PowerShell snappin on the Catch Block
Get-PSSnapin "Microsoft.SharePoint.PowerShell"

catch

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

Write-Host "Finished Adding PowerShell Snap-in" -ForegroundColor Green

Above lines can be used in any powershell script to get it started.

It is recommend that you use Windows PowerShell when performing command-line administrative tasks.

The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.


We will see it’s use in other powershell scripts in next post.


PowerShell Snap-in Sharepoint 2013



Adding PowerShell Snap-in Sharepoint 2013

No comments:

Post a Comment