none
PowerShell Script to find Created Date of site collections

    Question

  • Looking for a script I can use to get the date a site collection was created.

    If not in Powershell I could use C#

    Any help on this is greatly apprecitated.


    <Derek>

    Friday, September 21, 2012 1:27 PM

Answers

  • Gentlemen, thank you for the direction...

    Here is what I ended up with... exactly how I envisioned it


    $siteUrl = <webapp url>
    date
    $old = ($date.AddDays(-30))
    $rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
    $spWebApp = $rootSite.WebApplication
     
    foreach($site in $spWebApp.Sites)
    {
        foreach($sites in $site.RootWeb)
        {
           if($sites.created -ne $null)
           {
               Foreach($siteOld $sites | Where-object {$_.created -lt $old })
                {         
                  $sites.url + "_____" +$sites.created.ToShortDateString()
                 }
           }
        }
        $site.Dispose()
    }
    $rootSite.Dispose()


    <Derek>




    • Marked as answer by Derek.Wilkes Friday, September 21, 2012 4:48 PM
    • Edited by Derek.Wilkes Friday, September 21, 2012 4:56 PM
    Friday, September 21, 2012 4:47 PM

All replies

  • Its actually pretty simple

    $w = Get-SPWeb http://sitename

    $w.Created


    Paul Stork SharePoint Server
    MVP Senior Solutions Architect: BlueChip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

    • Marked as answer by Derek.Wilkes Friday, September 21, 2012 4:18 PM
    • Unmarked as answer by Derek.Wilkes Friday, September 21, 2012 4:43 PM
    Friday, September 21, 2012 2:11 PM
  • To get the date for all site collections:

    $Sites=@();
    Get-SPSite -limit ALL|%{
    
    $RootWeb = $_.RootWeb;
    
    $Created = $RootWeb.Created;
    
    $Sites += New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created=$Created}
    
    $RootWeb.Dispose();
    $_.Dispose();
    }
    $Sites|Export-CSV "C:\SiteCollectionCreated.csv" -NoTypeInformation;

    Friday, September 21, 2012 2:26 PM
  • And this what I get....

    Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error:
     "Root element is missing."
    At line:1 char:7
    + $Sites <<<< =@();
        + CategoryInfo          : MetadataError: (:) [], ArgumentTransformationMet
       adataException
        + FullyQualifiedErrorId : RuntimeException

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

    Method invocation failed because [System.Xml.XmlDocument] doesn't contain a met
    hod named 'op_Addition'.
    At line:8 char:10
    + $Sites += <<<<  New-Object PSObject -Property @{SiteUrl=$RootWeb.Url; Created
    =$Created}
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
       meException
        + FullyQualifiedErrorId : MethodNotFound

                                   

    <Derek>

    Friday, September 21, 2012 3:45 PM
  • Now loop to find all SC's in a WebApp?

    <Derek>

    Friday, September 21, 2012 3:51 PM
  • Gentlemen, thank you for the direction...

    Here is what I ended up with... exactly how I envisioned it


    $siteUrl = <webapp url>
    date
    $old = ($date.AddDays(-30))
    $rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
    $spWebApp = $rootSite.WebApplication
     
    foreach($site in $spWebApp.Sites)
    {
        foreach($sites in $site.RootWeb)
        {
           if($sites.created -ne $null)
           {
               Foreach($siteOld $sites | Where-object {$_.created -lt $old })
                {         
                  $sites.url + "_____" +$sites.created.ToShortDateString()
                 }
           }
        }
        $site.Dispose()
    }
    $rootSite.Dispose()


    <Derek>




    • Marked as answer by Derek.Wilkes Friday, September 21, 2012 4:48 PM
    • Edited by Derek.Wilkes Friday, September 21, 2012 4:56 PM
    Friday, September 21, 2012 4:47 PM
  • If you want an easier script, you might wanna use the following:
    Get-SPSite -Limit All | %{$root = $_.rootweb; $date = $root.created.toShortDateString(); Write-Host "$($root.url) created on $($date)"}



    Nico Martens - MCTS, MCITP
    SharePoint 2010 Infrastructure Consultant / Trainer
      

    Friday, September 21, 2012 5:22 PM
  • colle script! saved time. many thanks (to Nico Martens)

    Get-SPSite -Limit All | %{$root = $_.rootweb; $date = $root.created.toShortDateString(); Write-Host "$($root.url) created on $($date)"}

    • Edited by struchev Wednesday, September 4, 2013 7:33 AM
    Wednesday, September 4, 2013 7:31 AM