Monday 3 February 2014

Sharepoint PowerShell Commands

Please find below power shell Command For Reference


Error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
==================================================================
Change Service as "local System" to "Network service" or "Current user"


Filter Pages getting error
===================
Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Microsoft SharePoint Foundation-compatible HTML editor such as Microsoft SharePoint Designer.
If the problem persists, contact your Web server administrator.

Solution: patch KB2844286 is upgraded.After uninstall patch it is working properly.

Change Form Administrator
===================
stsadm -o updatefarmcredentials -userlogin <domain\username> -password <newpassword>


Version Errors in site Restoring Syntax:
===========================
“PSConfig.exe -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures”


SharePoint PowerShell Enable
=============================
Add-PSSnapin Microsoft.SharePoint.PowerShell


Backup Site:
====================
Backup-SPSite -Identity http://test-pc/sites/PersonalPortal -path D:\PersonalPortal_05May2013.bak


Restore site:
=================
Restore-SPSite -Identity http://webdel16/sites/PersonalPortal -path D:\ProjectMaintanance\Personal\PersonalPortal_18JUN2013.bak -force


Creating .wsp file
===================
Creating .wsp file we need to Package solution only no need to deploy solution


Adding solution:
==================
Add-SPSolution D:\production\PML_LIPolicyManagementTimerJob.wsp

Add-SPSolution -LiteralPath D:\Personal\PML_Personal_Policy.wsp


Uninstall solution:
==================
Uninstall-SPSolution -Identity PML_Personal_Policy.wsp -allwebapplications

Uninstall-SPSolution -LiteralPath D:\Personal\PML_Personal_Policy.wsp


Remove solution:
==================
Remove-SPSolution -identity PML_Personal_Policy.wsp -force


Retract solution:
==================
Retract-SPSolution -LiteralPath D:\Personal\PML_Personal_Policy.wsp


Install solution:
==================
Install-SPSolution -Identity PML_Personal_Policy.wsp -allwebapplications

Install-SPSolution -Identity PML_Personal_Policy.wsp -GACDeployment

Install-SPSolution -Identity PML_Personal_Policy.wsp -LiteralPath D:\Personal\PML_Personal_Policy.wsp -GACDeployment

Install-SPSolution –Identity PML_Personal_Policy.wsp –WebApplication http://test-pc/ -GACDeployment -Force


Developer dash Board
==========================
stsadm -o setproperty -pn developer-dashboard -pv on
stsadm -o setproperty -pn developer-dashboard -pv off


Creating .wsp file
===================
Creating .wsp file we need to Pakage solution only


Activating Feature:
====================
stsadm.exe -o activatefeature -filename "PML_ExportToMoneyWorksTimerJob_Feature1\Feature.xml" -url http://test-pc/sites/PersonalPortal -force


DeActivating Feature:
====================
stsadm.exe -o deactivatefeature -filename "PML_ExportToMoneyWorksTimerJob_Feature1\Feature.xml" -url http://test-pc/sites/PersonalPortal -force


Export Document Library Syntax:
===============================
$web = get-spweb "http://test-pc/sites/PersonalPortal"
export-spweb $web -ItemUrl "Templates" -Path "D:\Templates.cmp"


Import Document Library Syntax:
==================================
$web = get-spweb "http://webdel16/sites/PersonalPortal"
import-spweb $web -Path "D:\Templates.cmp"


Add/Change Primary site collection administrator: 
=========================================
Get-SPSite http://test-pc/sites/PersonalPortal | Set-SPSite –Owner "Domain\SystemName"



Add/Change Secondary site collection administrator: 
========================================
Get-SPSite http://test-pc/sites/PersonalPortal | Set-SPSite –SecondaryOwner "Domain\SystemName"


Create Web application
======================
# Set variables
$WebAppName = "SharePoint - 500"
$WebAppHostHeader = "test-pc"
$WebAppPort = 500
$WebAppAppPool = "SharePoint1 - 500"
# This User has to be a Sharepoint Manager Account
$WebAppAppPoolAccount = "Domain\SystemName"
$WebAppDatabaseName = "WSS_Content_Personal"
$WebAppDatabaseServer = "test-pc\SharePoint"
# Create a new Sharepoint WebApplication
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL ("http://" + $WebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -DatabaseName $WebAppDatabaseName -DatabaseServer $WebAppDatabaseServer


Creating Site Collection
=========================
Get-SPWebTemplate
$SiteURL = "http://test-pc/sites/test2"
$SiteTitle= "Test Site"
$template = Get-SPWebTemplate "STS#0"
New-SPSite -Url $SiteURL -OwnerAlias "test-pc\webdel16" -Template $template
$Web = Get-SPWeb $SiteURL
$Web.title = $SiteTitle
$Web.update()


Check web Application is Exist or NOT
=========================================
Get-SPWebApplication http://test-pc/sites/PersonalPortal
if(Get-SPWebApplication http://test-pc/){Write-Host "WebApplication Exists"}



Check Application Pool
=======================
Get-SPServiceApplicationPool
Test-Path "IIS:\AppPools\DefaultAppPool"


Deleting Records From LIST
===========================
$SITEURL = "http://test-pc/sites/PersonalPortal/"

$site = new-object Microsoft.SharePoint.SPSite ( $SITEURL )

$web = $site.OpenWeb()

"Web is : " + $web.Title

# Enter name of the List below insted of LIST NAME

$oList = $web.Lists["GI Proposal"];

"List is :" + $oList.Title + " with item count " + $oList.ItemCount

$collListItems = $oList.Items;

$count = $collListItems.Count - 1


for($intIndex = $count; $intIndex -gt -1; $intIndex--)
{

"Deleting record: " + $intIndex

$collListItems.Delete($intIndex);

}

To attach an existing content database:
===================================
Mount-SPContentDatabase "<ContentDb>" -DatabaseServer "<DbServer>" -WebApplication http://SiteName


To detach a content database:
===================================
Dismount-SPContentDatabase "<ContentdBName>"


No comments:

Post a Comment