SharePoint Online: Get Site Collection Created Date using PowerShell

Requirement: Get Site Collection creation date in SharePoint Online.

SharePoint Online: PowerShell to Get Site Creation Date
How to check SharePoint online site creation date? Well, There is no UI to get site creation date in SharePoint Online or in On-Premises. However, PowerShell can help to find SharePoint online site collection created date.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Set parameter values
$SiteURL="https://crescent.sharepoint.com/sites/Ops"

Try { 
        #Get Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        
        #Get the Web
        $Web = $Ctx.Web
        $Ctx.Load($web)
        $Ctx.ExecuteQuery()

        #sharepoint online powershell get site creation date
        Write-host -f Green "Site Collection Created Date:"$Web.created.toShortDateString()
     }
    Catch {
        write-host -f Red "Error Getting Site Collection Creation Date!" $_.Exception.Message
   }
This PowerShell gets the site collection created date!

Get Created Date of All SharePoint Online Site Collections in Office 365 Tenant:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput="C:\Temp\SiteCreatedDate.csv"
 
Try {
    #Get Credentials to connect
    $Cred = Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Connect to SharePoint Online Admin Center
    Connect-SPOService -Url $AdminSiteURL –Credential $Cred
 
    #Get All site collections
    $SiteCollections = Get-SPOSite -Limit All
    Write-Host "Total Number of Site collections Found:"$SiteCollections.count -f Yellow
 
    #Array to store Result
    $ResultSet = @()
 
    #Loop through each site collection and retrieve details
    Foreach ($Site in $SiteCollections)
    {
        Write-Host "Processing Site Collection :"$Site.URL -f Yellow
 
        Try {
            #Get the Root web of the Site collection
            $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Site.URL)
            $Ctx.Credentials = $Credentials  
            $RootWeb=$Ctx.Web
            $Ctx.Load($RootWeb)
            $Ctx.ExecuteQuery()
            $CreatedDate = $RootWeb.created.toShortDateString()
        }
        Catch {    
            write-host -f Red "`tError Getting Root Web:" $_.Exception.Message
        }

        #Get site collection details    
        $Result = new-object PSObject
        $Result | add-member -membertype NoteProperty -name "Title" -Value $Site.Title
        $Result | add-member -membertype NoteProperty -name "Url" -Value $Site.Url
        $Result | add-member -membertype NoteProperty -name "CreatedDate" -Value ($CreatedDate)
        $ResultSet += $Result
    }  
    #Export Result to csv file
    $ResultSet |  Export-Csv $ReportOutput -notypeinformation  
    Write-Host "Site Creation Date Report Generated Successfully!" -f Green
}
Catch {    
    write-host -f Red "Error:" $_.Exception.Message
}


PnP PowerShell to Get Site Collection Created Date in SharePoint Online:
#Config Variable
$SiteURL = "https://crescenttech.sharepoint.com/Sites/Marketing"

#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Root Web with "created" property
$Web = Get-PnPWeb -Includes Created

#Get Site Collection Created Date
Write-host "Site Collection Created on:"$Web.Created 
SharePoint Online: Get Site Collection Created Date using PowerShell SharePoint Online: Get Site Collection Created Date using PowerShell Reviewed by Salaudeen Rajack on September 02, 2017 Rating: 5

3 comments:

  1. How can you capture this for all site collections?

    ReplyDelete
  2. Hi, is there a way to capture the created date of a subsite too?

    ReplyDelete
    Replies
    1. Yes, the script actually gets the created date of the "Root Web", So just enter the $SiteURL variable value to a Subsite URL!

      Delete

Please Login and comment to get your questions answered!

Powered by Blogger.