Search This Blog

Tuesday, October 21, 2014

SharePoint 2010 Windows PowerShell Interview Questions

Q. What is Windows Powershell ?
Ans. Windows PowerShell is a new Windows command-line shell designed especially for system administrators. In the SharePoint administration context, Windows PowerShell is another administration tool that supersedes the existing Stsadm.exe.


Q. How is Windows Powershell different from Stsadm ?
Ans. Unlike stsadm, which accept and return text, Windows PowerShell is built on the Microsoft .NET Framework and accepts and returns .NET Framework objects. In addition to that it also gives you access to the file system on the computer so that you can access registry,digital signature certificate etc..


Q. What are cmdlet's?
Ans. Windows PowerShell introduces the concept of a cmdlet which are simple build in commands, written in a .net language like C# or VB.


Q. Can you Create PowerShell scripts for deploying components in SharePoint ?
Ans. If you are creating a webpart with VS 2010 then you can deploy it using ctrl + f5. However, to activate the webpart feature you can write a powershell script (.ps1) and execute it after dpeloyment.


Q. Where is Powershell located in sharePoint ?
Ans. On the Start menu, click All Programs -> Click Microsoft SharePoint 2010 Products -> Click SharePoint 2010 Management Shell.


Q. If you need going to install a webpart or any custom solution in SharePoint 2010 using PowerShell What permissions do you need?
Ans. In order to use Windows PowerShell for SharePoint 2010 Products, a user must be a member of the SharePoint_Shell_Access role on the configuration and content database. In addition to this, the user must also be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint 2010 Products is installed. See  The Details below


Permissions for Windows PowerShell - SPShellAdmin


In order to use Windows PowerShell for SharePoint 2010 Products, a user must be a member of the SharePoint_Shell_Access role on the configuration and content database. In addition to this, the user must also be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint 2010 Products is installed.


To add a user as SharePoint_Shell_Access on the SharePoint database use the below powershell cmdlet :
Add-SPShellAdmin


Please Note that to run the above cmdlet you must have* Membership in the securityadmin fixed server role on the SQL Server instance
* Membership in the db_owner fixed database role on all affected databases
* and local administrative permission on the local computer.



In addition to above some important things to Note:


* The user gets added to the WSS_Admin_WPG group on all Web servers when the user is added to the SharePoint_Shell_Access role.
* If the target database does not have a SharePoint_Shell_Access role, the role is automatically created.
* If you use the database parameter, the user is added to the role on the farm configuration database, the Central Administration content database, and the specified database. Using the database parameter is the preferred method because most of the administrative operations require access to the Central Administration content database. The cmdlet is something like below :


Add-SPShellAdmin -UserName Domainname\User -database {Database GUID}


Q. How to list all the commands in PowerShell ?
Ans. Get-Command * commands gets you all the Powershell commands. For more commands see 
To Open the Windows PowerShell Session :


1. On the Start menu, click All Programs.
2. Click Microsoft SharePoint 2010 Products.
3. Click SharePoint 2010 Management Shell


Note : You should have SharePoint_Shell_Access role on the configuration database and you should be a member of the WSS_ADMIN_WPG local group on the computer where SharePoint Server 2010 is installed.


Some of the Common Commands and Operations are: 


Create Web Application Variable 
$webapp = Get-SPWebApplication "http://pravahaminfol234/"


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 <http://sitename/> -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


Adding a content database using PowerShell in SharePoint 2010
To attach an existing content database:
Mount-SPContentDatabase "" –DatabaseServer "" –WebApplication http://webapplicationname/
is the content database to be attached.
is the name of the database server.
http://webapplicationname/ is the name of the Web application to which the content database is being attached.
To detach a content database:
Dismount-SPContentDatabase ""
Where is the name of the content database.


SharePoint 2010 Windows PowerShell Commands - II 
Some more PowerShell Commands
Site Collection Commands


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 :
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 access 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

No comments:

Post a Comment