LinkedIn

Thursday, April 17, 2014

SharePoint PowerShell Commands

 Site Collection Backup
Backup-SPSite -Identity -Path [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose] 

Site Collection Restore
Restore-SPSite -Identity -Path< Backup file> [-DatabaseServer ] [-DatabaseName ] [-HostHeader ] [-Force] [-GradualDelete] [-Verbose]

Export Site
Export-SPWeb -Identity -Path [-ItemUrl ] [-IncludeUserSecurity] [-IncludeVersions] [-NoFileCompression] [-GradualDelete] [-Verbose]
Import Site 
Import-SPWeb -Identity -Path [-Force] [-   NoFileCompression] [-Verbose]
Get all site details

$a = Get-SPWebApplication "<  $a | Select RootWeb, Url, Owner > c:\emea.csv
 $a | Select RootWeb, Url, Owner | Format-Table -AutoSize >data.csv

Deploy BDC from PowerShell
$metaStore = Get-SPBusinessDataCatalogMetadataObject -BdcObjectType "Catalog" -ServiceContext < Import-SPBusinessDataCatalogModel -Path "D:\Droppoint\test.bdcm" -Identity $metaStore -Force

Get Database names of sites
Get-SPContentDatabase | %{Write-Output "- $($_.Name)”; foreach($site in $_.sites){write-Output $site.url}} > C:\sitecollections.txt

Site Collection Sizes
Get-SPSite -Limit ALL | select url, ContentDatabase, Owner, @{label="Size in MB";Expression={$_.usage.storage/1MB}} | Sort-Object -Descending -Property "Size in MB" | Format-Table –AutoSize | Out-String -Width 100000 > D:\CollectionSize.txt
 
Get all Sub Site names
$site = Get-SPSite "http://yoursite"
 foreach ($web in $site.AllWebs) { 
  $web | Select-Object -Property Title,Url,WebTemplate   
}  
$site.Dispose()

 Search for Correlation ID in ULS logs
 
$term= ''
Select-String -pattern "$term" -Path E:\SPLogs\ULS\*.* -list

Mount and Unmount the DB

Dismount-SPContentDatabase ""
Mount-SPContentDatabase "" -DatabaseServer "" -WebApplication http://mysitename
 
Site Collections and its DB names
 Get-SPContentDatabase | %{Write-Output "- $($_.Name)”; foreach($site in $_.sites){write-Output $site.url}}
 Get Servers in Farm
 Get-SPServer
  
Get All Application Servers in Farm
 get-spserver | ? { $_.Role -eq "Application" }
 
Content Database Size
 Get-SPDatabase | select name, disksizerequired| Sort-Object disksizerequired -desc| Format-Table –AutoSize > c:\contDBSize.csv
 Storage Details of Site Collection

Get-SPSite -Limit 5| Select URL, @{Name=”Storage”; Expression={“{0:N2} MB” -f ($_.Usage.Storage/1000000)}}, @{Name=”Quota”; Expression={“{0:N2} MP” -f ($_.Quota.StorageMaximumLevel/1000000)} } | Format-Table –AutoSize | Out-string -width 10000 > C:\output.csv
 
To avoid truncation of PowerShell output: $FormatEnumerationLimit =-1
Site Owners
 
Get-SPWebApplication | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, ID, ParentWebID,@{Name=’SiteAdministrators’;Expression={[string]::join(";", ($_.SiteAdministrators))}} | Export-CSV C:\InfoArch.csv -NoTypeInformation

Orphaned Database

$orphanedDB = Get-SPDatabase | where{$_.Name -eq "MyContentDatabase"}

$orphanedDB.Delete()


Reference:
http://praveeniyer7.blogspot.in/p/sharepoint-powershell-commands.html