Tag Archives: SharePoint Sites

Export-SPAllSitesForMigration


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]
RequiredYes
DescriptionUse this parameter to specify the output CSV filename.
Parameter Name
$OutGrid
Data Type[Switch]
RequiredNo
DescriptionUse 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

SharePoint Sites versus Webs

SharePoint Sites versus Webs

This is a post I wrote long ago for my previous blog. I’ve been asked what the difference is between Site and Web; here I’m going to tackle that question head on!

First and foremost, Microsoft didn’t make the differentiation of these two easy to follow as they use the terms interchangeably. In this article I’ll be describing the technical naming conventions and how to simplify this for non-technical business users.

For reference, I’m using the term Site (SPSite) to indicate a Site Collection and Web (SPWeb) to reference an actual web site. These are the technical internal terms used.

The first thing to remember about a SharePoint Site, for both on-premise and Office 365, is it’s just a site. Same for a Web, it is just a website. What makes each of these unique are the features enabled for that specific template and the content types to display pages on those Webs.

Site Collection

A Site Collection is a container of Webs. Every Site Collection has a single top-level Web. The top-level Web can have zero to many sub-webs.

From a development perspective, a Site Collection can be created or accessed via the SPSite class.

Web

A Web is the actual web site.

From a development perspective, a Web can be created or accessed via the SPWeb class.

Below is an image that describes the Site Collection and Web relationships.

Working with End Users

When working with non-technical end users, you may just wish to use the terms Site Collection and Site. There’s no need to confuse them with the internal class/object names.

Conclusion

In SharePoint, a site is just a site and a web is just a web; they are all fundamentally the same with different features enabled. For example, a Publishing site is just a site collection with the Publishing feature enabled.

Don’t hesitate to ask questions if you need additional information!

SharePoint on!