Hi
Friends,
This
blog is about commonly used power shell command used in SharePoint 2013 and
SharePoint 2010. I have tested all these commands in SharePoint 2013.
Power shell is
executed from SharePoint 2010/2013 management Shell.
è Adding
WSP :
ð Farm
solution:
Add-SPSolution -LiteralPath <Path of wsp>
Eg: Add-SPSolution -LiteralPath c:\contoso_solution.wsp
ð Sandbox
Solution:
Add-SPUserSolution
–LiteralPath < path of wsp> -site < site ulr>
è Deploy
Installed solution
ð Farm
Solution:
Install-SPSolution -Identity <Web part Name.wsp> -GACDeployment
Eg: Install-SPSolution -Identity contoso_solution.wsp –GACDeployment
ð Sandbox
Solution:
Install-SPUserSolution
–identity wspfilename.wsp –site <site url>
Eg: Install-SPUserSolution
–identity wspfilename.wsp –site <site url>
è Update
Existing
ð Farm
Solution:
Update-SPSolution -Identity <wsp name> -LiteralPath <WSP Path> -GACDeployment
Eg: Update-SPSolution -Identity my.wsp -LiteralPath c:\my.wsp –GACDeployment
ð Sandbox
Solution:
Update-SPUserSolution -Identity contoso_solution.wsp -Site http://sitename -ToSolution contoso_solution_v2.wsp
Eg: Update-SPUserSolution -Identity my.wsp -Site http://sitename -ToSolution myv2.wsp
è Uninstall
Solution :
ð Farm
Solution:
Uninstall-SPSolution [-Identity] <SPSolutionPipeBind> -WebApplication <SPWebApplicationPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <String>] [-Confirm [<SwitchParameter>]] [-Language <UInt32>] [-Local <SwitchParameter>] [-Time <String>] [-WhatIf [<SwitchParameter>]]
Eg: Uninstall-SPSolution –Identity http://sitename contoso_solution.wsp
ð Sandbox
Solution:
Uninstall-SPUserSolution [-Identity] <SPUserSolutionPipeBind> -Site <SPSitePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
Eg: Uninstall-SPUserSolution -Identity my.wsp -Site http://sitename
è Remove
Solution:
ð Farm
Solution:
Remove-SPSolution [-Identity] <SPSolutionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-Language <UInt32>] [-WhatIf [<SwitchParameter>]]
Eg: Remove-SPSolution -Identity contoso_solution.wsp
ð Sandbox
Solution:
Remove-SPUserSolution [-Identity] <String> -Site <SPSitePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
Eg: Remove-SPUserSolution -Identity contoso_solution.wsp -Site http://sitename
è Get
List of Solution
ð Farm
Solution:
Get-SPSolution
ð Sandbox
Solution:
Get-SPUserSolution
–Site <site name>
è Install
Feature:
ð Farm
Solution:
Install-SPFeature [-Path] <String> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
Eg: Install-SPFeature -path "MyCustomFeature"
è
Enable Feature: The Enable-SPFeature cmdlet
enables an installed feature at the given scope.
ð Farm
Solution:
Enable-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-PassThru <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
Eg: Enable-SPFeature -identity "Feature Folder path" -URL http://somesite
è Deactivate
Feature:
ð Farm
Feature:
Disable-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-Url <String>] [-WhatIf [<SwitchParameter>]]
Eg: Disable-SPFeature –identity "MyCustom" -URL http://somesite
è
Uninstall/ Delete Feature: The Uninstall-SPFeature cmdlet
removes the specified feature definition from the collection of feature
definitions in the farm.
ð Farm
Solution:
Uninstall-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
Eg: Uninstall-SPFeature -Identity "MyCustomFeature"
è Get
List of active features: It
displays feature name and corresponding ID:
è To
Delete unused web parts from Solution Store: .webpart file is not deleted from web part gallery
after executing above commands, user needs to run bellow command to delete
(.webpart) from gallery.
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$camlQuery = '<Where><Eq><FieldRef
Name="FileLeafRef" /><Value
Type="Text">TestgiriWebPart_GiriWebPart.webpart</Value></Eq> </Where>'
$spQuery.Query = $camlQuery
$site = Get-SPSite -Identity
"http://win-ua50t4mr5s4"
$webpartgallery = $site.GetCatalog(
[Microsoft.SharePoint.SPListTemplateType]::WebPartCatalog)
$webparts = $webpartgallery.GetItems($spQuery)
$webparts[0].Recycle()
è To
get details about the feature and web application: If you are not sure what Web the
feature is activated in, run the following:
Get-SPSite
http://SharePointSite/ |
Get-SPWeb -Limit ALL | %{
Get-SPFeature -Web $_ } | Sort
DisplayName -Unique | FT DisplayName,Id
è Delete
Feature:
Uninstall-SPFeature
<Feature ID>
è To
See List of solutions in Solution store:
Stsadm -o
EnumSolutions
è Backup
and Restore:
ð Backup
SharePoint FARM:
Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential} [-Verbose]
Eg: Backup-SPFarm c:\SPBackup\myfarm.bak
–BackupMethod Full
ð Backup
Site Collection:
Backup-SPSite -Identity <SiteCollectionGUIDorURL> -Path <BackupFile> [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]
Eg: Backup-SPSite –identity http://siteName/ -path c:\mysite.bak –force
è Restore
Backup
ð Restore
Server Farm:
Restore-SPFarm -Directory <BackupFolder> -RestoreMethod Overwrite [-BackupId <GUID>]
Eg: Restore-SPFarm -Directory \\file_server\share\Backup -BackupId 12345678-90ab-cdef-1234-567890abcdef -RestoreMethod new -ConfigurationOnly
ð Restore Site Collection:
Restore-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-DatabaseServer DatabaseServerNameHere] [-DatabaseName ContentDatabaseNameHere] [-HostHeader HostHeaderHere] [-Force] [-GradualDelete] [-Verbose]
Eg: Restore-SPSite –identity http://mysite -path c:\myback.bak -force
è SharePoint
list backup: To
backup SharePoint list we need to use SharePoint management shell
ð Exporting
List
Export-SPWeb http://www.domain.com -itemurl
"/Lists/NameList" -path "c:\test.cmp”
ð Importing
List:
Import-SPWeb http://www.domain.com -Path
"c:\test.cmp"
Commonly used power
shell command:
ð Removing
Web application
Remove-SPWebApplication -identity
http://sitename –Confirm
ð Delete
Web Application Pool
Remove-WebAppPool -name ‘applicationPoolName’
ð Remove
Web Application , Content Database and IIS Application Pool
Remove-SPWebApplication
http://sitename -Confirm -DeleteIISSite -RemoveContentDatabases
Export
list:
#
specify the site URL to export
$web
= Get-SPWeb "http://testsite:9000"
#
specify output folder to store exported lists
$path
= "c:\ListBackup\"
foreach($list
in $web.lists)
{
"Exporting " + $list.RootFolder.URL
Export-SPWeb $web.URL -ItemUrl $list.URL -path
($path + $list + ".cmp") -nologfile
}
Export-SPWeb
http://tawasul/IT/ISC/ -ItemUrl "/Lists/List_Name" -path
"c:\ExportISC\List_Name.cmp"
Export-SPWeb
http://mysite/sites/KPI/ -ItemUrl "/Lists/" -path
"c:\Export_KPI\List_Name.cmp"
è
Re-Indexing
SharePoint List:
UPDATE
<Content DB>.dbo.AllListsAux set NextAvailableId=1 where
ListID='<GUID>'
eg:
UPDATE
WSS_RQMS.dbo.AllListsAux set NextAvailableId=1 where
ListID='{500440F9-EEFE-4659-9D33-B90F68404DD4}'
è
Adding
Column to existing SharePoint List using powershell:
param([string]$workspaceUrl)
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
{
$site = SPSite($workspaceUrl)
$web = $site.RootWeb
$spList = $web.Lists["YourList"]
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$spList.Fields.Add("YourColumn",$spFieldType,$false)
$spList.Update()
}
)
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
{
$site = SPSite($workspaceUrl)
$web = $site.RootWeb
$spList = $web.Lists["YourList"]
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$spList.Fields.Add("YourColumn",$spFieldType,$false)
$spList.Update()
}
)
To
Execute: Save this file in your local drive execute as bellow:
PS
C:\Administrator> .\YourScript.ps1 -workspaceUrl "yoururl"
Eg:
PS C:\Administrator> C:\MyScript.ps1 -workspaceUrl "http://mymachinename:9000"
è
Create database from power shell:
New-SPConfigurationDatabase
[-DatabaseName] <String> [-DatabaseServer] <String>
[[-DirectoryDomain] <String>] [[-DirectoryOrganizationUnit]
<String>] [[-AdministrationContentDatabaseName] <String>]
[[-DatabaseCredentials] <PSCredential>] [-FarmCredentials]
<PSCredential> [-Passphrase] <SecureString> [-AssignmentCollection
<SPAssignmentCollection>]
è
Changing Site Logo:
$sitename=
"http:// dev/sites/SiteName"
$sitelogo=
"http:// dev/Site Assets/sitelogo.jpg"
$site=new-object
Microsoft.SharePoint.SPSite($sitename)
$web=$site.OpenWeb()
$web.SiteLogoUrl=$sitelogo
$web.Update()
$site.Dispose()
è
Cleanup Deleted Database from
SharePoint server:
ð
Display
list of all database
Get-SPdatabase
ð
This
will list all databases in SharePoint that no longer exist on the database
server.
Get-SPDatabase
| where {$_.exists -eq $false} :
ð
Remove
all orphan database:
Get-SPDatabase
| where {$_.exists -eq $false} | foreach {$_.delete()}
è
Get List of Application Pool:
ð
Get
list of application Pool:
Get-SPServiceApplicationPool
ð
Delete
Application Pool:
Remove-SPServiceApplicationPool-Identity
<Name of the application pool>
è
Change Master Page :
$web
= Get-SPWeb http://sharepoint
$web.CustomMasterUrl
= "/_catalogs/masterpage/seattle.master"
$web.MasterUrl
= "/_catalogs/masterpage/ seattle.master"
$web.Update()
è
Get List of Web Application in a
Farm:
Get-SPWebapplication
è
Get
List of Site collection in a Web Application:
Get-SPWebApplication
<WebAppURL> | Get-SPSiteAdministration -Limit ALL| Select url,Title
Eg:
Get-SPWebApplication http:// dev/ |
Get-SPSiteAdministration -Limit ALL| Select url,Title
è
List all the Web Application and
Site collection and sub sites
Get-SPSite
è
Remove
a WebApplication, content database, Application Poo:
Remove-SPWebApplication
http://win-2k8-dc7:8081 -Confirm -DeleteIISSite –RemoveContentDatabases
è
To Create new Web Application:
$ap =
New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication
-DisableKerberos
New-SPWebApplication
-Name "WEBAPP" -Port 80 -URL "http://WebAppqa"
-ApplicationPool "WEBAPPApplicationPool" -ApplicationPoolAccount
(Get-SPManagedAccount "domain\spadmin") -DatabaseName
"WSS_Content_WEBAPPRootDB" –AuthenticationProvider $ap
è
To attached SharePoint content
database from one server to another server:
ð
Dismount database from source server:
Dismount-SPContentDatabase [-Identity] <SPContentDatabasePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
Eg:
Dismount-SPContentDatabase
<database name>
ð
Mount
Database to new server:
Mount-SPContentDatabase
"<ContentDb>" -DatabaseServer "<DbServer>"
-WebApplication http://SiteName
è
Crate
Site collection:
New-SPContentDatabase
-Name WSS_Content_WEBAPP_TestSite -WebApplication
http://WebApp:8080/
New-SPSite
http://WebApp:8080/sites/TestSite -OwnerAlias "domain\sAdmin"
-ContentDatabase WSS_Content_WEBAPP_TestSite-Name "TestSite"
-Template "PROJECTSITE#0"
Regards
Gireesh Painuly..
No comments:
Post a Comment