Table of Contents
[toc]
Function Name
Export-SPAllSitesForMigration
Download Source Code
Export-SPAllSitesForMigration.zip
Description
The code in this module will gather all site collections in your farm and write the details to a CSV file. The CSV file will be formatted to support a migration effort.
Parameters
Parameter Name | $CsvFilename |
Data Type | [System.String] |
Required | Yes |
Description | Use this parameter to specify the output CSV filename. |
Parameter Name | $OutGrid |
Data Type | [Switch] |
Required | No |
Description | Use to indicate if you’d like an output grid before returning. Using this during the initial build of your migration to see that all site information is included as expected. |
Return Value
This function returns an array of custom PS objects. Each object contains the following properties:
[System.String] | Migrate |
[System.String] | SourceSiteName |
[System.String] | SourceSiteUrl |
[System.String] | SourceDatabaseName |
[System.String] | SourceWebApplicationName |
[System.String] | SourceSiteTemplate |
[System.String] | DestinationWebApplicationUrl |
[System.String] | DestinationSiteUrl |
[System.String] | DestinationSiteTemplate |
Code
<#
# Export-SPAllSitesForMigration
#
# .Synopsis
# The code in this module will gather all site collections in your farm and write the details
# to a CSV file.
#
# .Description
# The code in this module will gather all site collections in your farm and write the details
# to a CSV file. The CSV file will be formatted to support a migration effort.
#
# .Notes
# This script must be run on one of the source farm servers. I usually run this on a secondary
# application server; in most cases where I build the farm, this will be SPAPP02 server.
#
# .Author
# Written by Bob Mixon
#>
cls
# Load PowerShell cmdlet's for SharePoint
if((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
}
<#
# Export-SPAllSitesForMigration
#
# .Synopsis
# The code in this function will gather all site collections in your farm and write the details
# to a CSV file.
#
# .Description
# The code in this function will gather all site collections in your farm and write the details
# to a CSV file. The CSV file will be formatted to support a migration effort.
#
# .Notes
# This script must be run on one of the source farm servers. I usually run this on a secondary
# application server; in most cases where I build the farm, this will be SPAPP02 server.
#
# .Parameter $CsvFilename
# Required - Use this parameter to specify the output CSV filename.
#
# .Parameter $OutGrid
# Optional - Use to indicate if you'd like an output grid before returning. Using this during
# the initial build of your migration to see that all site information is included
# as expected.
#
# .Returns
# This function returns an array of custom PS objects. Each object contains the following
# properties:
#
# String Migrate
# String SourceSiteName
# String SourceSiteUrl
# String SourceDatabaseName
# String SourceWebApplicationName
# String SourceSiteTemplate
# String DestinationWebApplicationUrl
# String DestinationSiteUrl
# String DestinationSiteTemplate
#
# .Example
# Export-SPAllSitesForMigration -CsvFilename "c:\spreports\allsites.csv" -OutGrid
#
# .Author
# Written by Bob Mixon
#>
function Export-SPAllSitesForMigration
{
Param(
[Parameter(Mandatory=$true)]
[string]$CsvFilename,
[Parameter(Mandatory=$false)]
[switch]$OutGrid = $false
)
# Retrieve all site collections.
Write-Host "RETRIEVING ALL SITE COLLECTIONS TO BE MIGRATED" -ForegroundColor Yellow
# $oSites results in an array of SPSite objects.
$oSites = Get-SPSite -Limit ALL
Write-Host "Completed the retrieval of all site collections."
Write-Host "Building an array of all site collections to be exported and returned: " -NoNewline
# Array to contain all sites to migrate objects.
$aSitesToMigrate = @()
$oSites | ForEach-Object {
$sSourceSiteTemplateName = ([Microsoft.SharePoint.SPSite]$_).RootWeb.WebTemplate.ToString()
$sSourceSiteTemplateId = ([Microsoft.SharePoint.SPSite]$_).RootWeb.WebTemplateId.ToString()
$sSourceSiteTemplate = [String]::Format("{0}#{1}", $sSourceSiteTemplateName, $sSourceSiteTemplateId)
$oSiteToMigrate = New-Object -TypeName PSObject -Property @{
Migrate = "NO"
SourceSiteName = $_.RootWeb.Title
SourceSiteUrl = ([Microsoft.SharePoint.SPSite]$_).Url
SourceDatabaseName = ([Microsoft.SharePoint.SPSite]$_).ContentDatabase.Name
SourceWebApplicationName = ([Microsoft.SharePoint.SPSite]$_).WebApplication.Name
SourceSiteTemplate = $sSourceSiteTemplate
DestinationWebApplicationUrl = ""
DestinationSiteUrl = ""
DestinationSiteTemplate = $sSourceSiteTemplate
}
$aSitesToMigrate += $oSiteToMigrate
}
Write-Host "Success!" -ForegroundColor Green
if($OutGrid)
{
$aSitesToMigrate | Select-Object Migrate, SourceSiteName, SourceSiteUrl, SourceDatabaseName, `
SourceWebApplicationName, SourceSiteTemplate, DestinationWebApplicationUrl, DestinationSiteUrl, `
DestinationSiteTemplate | Out-Gridview
}
Write-Host ([string]::Format("Exporting site collection report to [{0}]: ", $CsvFilename)) -NoNewline
$aSitesToMigrate | Sort-Object SourceSiteUrl | Select-Object Migrate, SourceSiteName, SourceSiteUrl, SourceDatabaseName, `
SourceWebApplicationName, SourceSiteTemplate, DestinationWebApplicationUrl, DestinationSiteUrl, `
DestinationSiteTemplate | Export-CSV $CsvFilename -NoTypeInformation -Encoding UTF8
Write-Host "Success!" -ForegroundColor Green
return($aSitesToMigrate)
}
###################################################################################################
# Module Members to be Exported
###################################################################################################
#region Module Members to be Exported
if([System.IO.Path]::GetExtension($MyInvocation.ScriptName) -like ".psm1")
{
Export-ModuleMember -Function Export-SPAllSitesForMigration -ErrorAction SilentlyContinue
}
#endregion