Saturday, July 21, 2012

PowerShell capabilities/commands

Some of the Common Commands and Operations are:
Create Web Application Variable :
$webapp = Get-SPWebApplication http://WebapplicationUrl


Create SharePoint Site Variable (Instance of SPSite)
$siteurl = "http://MySharePointSite"
$Oursite=new-object Microsoft.SharePoint.SPSite($siteurl)



Here we have created a variable Oursite, which contains an instance of type SPSite. Now you can use it to display all webs in the site collection.
$Oursite.AllWebs more // List all Webs in the Site


Create Service Application Variable
$spapp = Get-SPServiceApplication -Name "ServiceApplicationDisplayName"


Create a Webapplication:
New -SPWebApplication -ApplicationPoolName -Name [ -Port ] [-HostHeader ] [-URL ][ -ApplicationPoolAccount ]


Delete WebApplication
Remove-SPWebApplication –identity -URL -Confirm


Create\Delete a Site Collection:
Create a Site collection:
  Get-SPWebTemplate
  $template = Get-SPWebTemplate "STS#0"
  New-SPSite –Url "" –OwnerAlias "" –Template $template


  Here $template is a Variable to store the type of template we want to use while creating a  site   collection.


Delete a Site Collection:
Remove-SPSite –Identity –GradualDelete
Here is a site Collection Url .


Back\Restore a content database


To Backup :
Backup -SPFarm -Directory -BackupMethod -Item [-Verbose]
Backup folder - is a folder to save your backup.
BackupMethod – Can Specify between Full or Differential.


To Restore:
Restore -SPFarm -Directory -RestoreMethod Overwrite -Item [-BackupId] [-Verbose]


If you don’t know the BackupID you can display all the backups using the below command and get the GUID of the Backup.
Get-SPBackupHistory -Directory
You can check all the Backup-Restore Operations Here


Deploy WebPart Soluiton Package
Install -SPWebPartPack -LiteralPath "PathToCABorwspFile" -Name "NameOFWebPart"
PathToCABorwspFile- is the full path to the CAB file that is being deployed.
NameOFWebPart- is the name of the Web Part that is being deployed.

Install Activate and Deactivate Feature using Windows Powershell
Install Feature :
$MyFeatureId = $(Get -SPFeature -limit all where {$_.displayname -eq "myfeatureName"}).Id
Install -SPFeature $MyFeatureId


Activate\Enable Feature :
$singleSiteCollection = Get -SPSite -Identity http://MySingleSiteCollectionURL
Enable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL


Deactivate\Disable Feature :
$singleSiteCollection = Get-SPSite -Identity http://MySingleSiteCollectionURL
Disable -SPFeature $MyFeatureId -Url $singleSiteCollection.URL


Command TO List all the PowerShell Commands
Get-Command –PSSnapin “Get-Command –PSSnapin “Microsoft.SharePoint.PowerShell” format-table name > C:\SP2010_PowerShell_Commands.txt

======================================================
Create Site Collection :
Get-SPWebTemplate
$template = Get-SPWebTemplate "STS#0"
New-SPSite -Url "" -OwnerAlias "" -Template $template

Delete Site Collection :

Remove-SPSite -Identity "URL of site Collection" -GradualDelete

Change Site collection Quotas :
Set-SPSite -Identity "SiteCollection Url" -MaxSize Quota


Add site Collection Administrators :Create Site Collection :

Set-SPSite -Identity "" -SecondaryOwnerAlias

Delete Site Collection :
Remove-SPSite -Identity "URL of site Collection" -GradualDelete


Change Site collection Quotas :
Set-SPSite -Identity "SiteCollection Url" -MaxSize Quota


Add site Collection Administrators :
Set-SPSite -Identity "" -SecondaryOwnerAlias ""


Lock or unlock a site collection :
Set-SPSite -Identity "Site Collection Url" -LockState ""


is one of the following vales :


# 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 acess to content completely. Users who attempt to access the site receive an access-denied message.

Create a site :New-SPSite "http://sitecollection/sites/Subsite -OwnerAlias "DOMAIN\UserName" –Language 1033


Set-SPSite -Identity "" -SecondaryOwnerAlias ""

Using Powershell to Export the Site
http://www.codeproject.com/Articles/271860/Sharpoint-2010-deployment-using-Powershell?display=Print

No comments:

Post a Comment