使用 PowerShell 获取 SharePoint 网站集创建日期
要求:我必须生成一份报告,以对上个月创建的网站集列表进行管理审查。
如何使用 PowerShell 获取网站创建日期?
要获取 SharePoint 网站集创建日期,我们可以使用 PowerShell,因为 SharePoint 中没有 UI 来查看网站创建日期!但您可以使用 PowerShell 在 SharePoint 中获取网站创建日期,如下所示:
Write-host (Get-SPSite "https://sharepointsite.com").RootWeb.created
让我们使用 PowerShell 根据 SharePoint 网站创建日期获取过去一个月创建的所有网站:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get all site collections
$SitesColl = Get-SPSite -Limit All
#Get start date of Last Last Month
$LastMonth= (Get-Date).AddMonths(-1)
#Loop through all sites
ForEach($Site in $SitesColl)
{
#Check site creation date
if($Site.RootWeb.created -gt $LastMonth)
{
$CreatedDate = $Site.RootWeb.created.toShortDateString()
Write-Host "$($Site.RootWeb.url) was created on $($CreatedDate)"
}
}
查找今天创建的所有网站集:
与上面的代码不同,让我们使用一行代码来查找今天创建的所有网站集:
Get-SPSite -Limit All | ? { $_.RootWeb.Created -eq[DateTime]::Today} | select Url, @{Name="Created";Expression={$_.RootWeb.Created}}
查找子网站的创建日期:
如何判断 SharePoint 网站何时创建?嗯,类似的代码适用于查找子网站的创建日期。
Get-SPweb "https://portal.crescent.com/credit" | Select @{Name="Created";Expression={$_.Created}}