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

[玩转系统] 如何使用 PnP PowerShell 获取 SharePoint 网站创建日期?

作者:精品下载站 日期:2024-12-14 05:19:39 浏览:14 分类:玩电脑

如何使用 PnP PowerShell 获取 SharePoint 网站创建日期?


最近,我的一位客户要求我获取 SharePoint Online 网站的创建日期。为此,我使用了 PnP PowerShell,它易于使用并可与 SharePoint 网站配合使用。在本教程中,我将向您展示如何使用 PnP PowerShell 获取 SharePoint 网站创建日期

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

如果您有权访问 SharePoint Online 管理中心,则可以从“活动网站”选项卡检查 SharePoint 网站的创建日期。

否则,PnP PowerShell 是获取 SharePoint 网站创建日期的另一个最佳选择。

这是完整的 PowerShell 脚本。

# Define the site collection URL
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"

# Connect to SharePoint Online
Connect-PnPOnline -Url $siteUrl -Interactive

# Retrieve the root web of the site collection
$web = Get-PnPWeb -Includes Created

# Retrieve the site collection creation date
$creationDate = $web.Created

# Display the creation date
Write-Host "The site collection was created on:" $creationDate

我使用 VS code 执行了上述 PnP PowerShell 脚本;您可以在此处看到它显示 SharePoint Online 网站的创建情况。

[玩转系统] 如何使用 PnP PowerShell 获取 SharePoint 网站创建日期?

在这里,我使用了 Get-PnPWeb PnP PowerShell cmdlet 和 -Inincludes Created 参数来获取根 Web 的创建日期。

如果你想重用代码,那么你可以创建一个如下所示的函数:

function Get-SPOCreationDate {
    param (
        [Parameter(Mandatory=$true)]
        [string]$SiteUrl
    )

    try {
        # Connect to SharePoint Online
        Connect-PnPOnline -Url $SiteUrl -Interactive

        # Retrieve the root web of the site collection
        $web = Get-PnPWeb -Includes Created

        # Retrieve the site collection creation date
        $creationDate = $web.Created

        # Display the creation date
        Write-Host "The site collection was created on:" $creationDate
    }
    catch {
        Write-Host "An error occurred:" $_.Exception.Message
    }
}

# Example Usage
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Get-SPOCreationDate -SiteUrl $siteUrl

每次用户传递 SharePoint 网站 URL 时,都会显示网站创建日期。

我希望本教程对您有所帮助,并且您现在已经了解如何使用 PnP PowerShell 获取 SharePoint Online 网站创建日期。仍有疑问,请随时在下面发表评论。

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

取消回复欢迎 发表评论:

关灯