当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 获取网站集创建日期

作者:精品下载站 日期:2024-12-14 14:43:41 浏览:15 分类:玩电脑

SharePoint Online:使用 PowerShell 获取网站集创建日期


要求:获取 SharePoint Online 中的网站集创建日期。

如何检查 SharePoint Online 网站创建日期?

如果您正在寻找一种方法来获取 SharePoint Online 中网站集的创建日期,PowerShell 是您的最佳选择。这对于报告或审计目的非常有用。在这篇博文中,我们将了解如何获取 SharePoint Online 中网站集的创建日期。让我们逐步完成获取创建日期所需的步骤!

要获取 SharePoint Online 网站集的创建日期,请执行以下操作:

  1. 登录 SharePoint 管理中心 >> 展开站点 >> 活动站点。
  2. 现在,站点列表在“创建日期”列中显示站点的创建日期(如果尚不存在,请将其添加到视图中!)

    [玩转系统] SharePoint Online:使用 PowerShell 获取网站集创建日期

SharePoint Online:使用 PowerShell 获取网站创建日期

PowerShell 可以帮助查找 SharePoint Online 网站集的创建日期:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\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
   }

此 PowerShell 获取网站集创建日期!在运行这些脚本之前,请确保您具有网站集管理员权限。

获取 Office 365 租户中所有 SharePoint Online 网站集的创建日期:

让我们获取租户中所有网站集的创建日期。


#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 在 SharePoint Online 中获取网站集创建日期:

使用 PnP PowerShell 在 SharePoint Online 中获取网站集的创建日期非常简单!


#Config Variable
$SiteURL = "https://crescent.sharepoint.com/Sites/Marketing"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#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 

让我们按创建日期排序所有网站集:


#Parameters
$TenantURL =  "https://crescent.sharepoint.com"
 
#Get Credentials to connect
$Credential = Get-Credential
 
#Frame Tenant Admin URL from Tenant URL
$TenantAdminURL = $TenantURL.Insert($TenantURL.IndexOf("."),"-admin")

#Connect to Admin Center
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Credential
 
#Get All Site collections - Filter BOT and MySite Host
$Sites = Get-PnPTenantSite -Filter "Url -like '$TenantURL'"

#Iterate through all sites
$SiteInventory = @()
$Sites | ForEach-Object {
    #Connect to each site collection
    Connect-PnPOnline -Url $_.URL -Credentials $Credential

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

    #Collect Data
    $SiteInventory += New-Object PSObject -Property  ([Ordered]@{
        "Site Name"  = $Web.Title
        "URL "= $Web.URL
        "Created Date" = $Web.Created
    })
}
#Sort Site Collection - Sort by Creation Date
$SiteInventory | Sort-Object 'Created Date' -Descending

了解 SharePoint Online 网站的创建日期可以帮助管理和审核您的 SharePoint 环境。通过这些简单的步骤,您可以使用用户界面或 PowerShell 轻松查找网站的创建日期。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯