ค้นหาเว็บไซต์

จะตรวจสอบว่าไซต์ SharePoint มีอยู่โดยใช้ PnP PowerShell ได้อย่างไร


เมื่อเร็วๆ นี้ ฉันกำลังทำงานกับสคริปต์อัตโนมัติเพื่อสร้างไซต์ SharePoint ฉันต้องการตรวจสอบว่ามีไซต์ SharePoint อยู่แล้วหรือไม่ ในบทช่วยสอนนี้ ฉันจะแสดงวิธีตรวจสอบว่าไซต์ SharePoint มีอยู่โดยใช้ PnP PowerShell หรือไม่

ตรวจสอบว่าไซต์ SharePoint มีอยู่โดยใช้ PnP PowerShell โดยใช้ Get-PnPTenantSite หรือไม่

ฉันจะแสดงวิธีการตรวจสอบว่ามีไซต์อยู่ใน SharePoint โดยใช้ PnP PowerShell โดยใช้ Get-PnPTenantSite PnP PowerShell cmdlet หรือไม่

ใน PnP PowerShell คุณสามารถใช้ Get-PnPTenantSite cmdlet เพื่อตรวจสอบว่าไซต์มีอยู่ใน SharePoint Online หรือไม่ cmdlet Get-PnPTenantSite ช่วยให้คุณสามารถดึงไซต์คอลเลกชันจากผู้เช่าได้ คุณสามารถใช้ cmdlet นี้เพื่อตรวจสอบว่ามีไซต์ใดไซต์หนึ่งอยู่หรือไม่

นี่คือตัวอย่าง

Connect-PnPOnline -Url "https://szg52.sharepoint.com" -Interactive

$siteUrl = "https://szg52.sharepoint.com/sites/accounting"
$site = Get-PnPTenantSite -Url $siteUrl -ErrorAction SilentlyContinue

if ($site) {
    Write-Output "The site 'accounting' exists."
} else {
    Write-Output "The site 'accounting' does not exist."
}

เนื่องจากในผู้เช่าของฉัน ไม่มีไซต์ที่พร้อมใช้งานเป็น "การบัญชี" จึงแสดงผลลัพธ์เช่น "ไม่มีไซต์ 'การบัญชี'" คุณสามารถตรวจสอบได้ในภาพหน้าจอด้านล่าง

คุณยังสามารถใช้ Where with the Get-PnPTenantSite cmdlet ได้ดังนี้:

Connect-PnPOnline -Url "https://szg52.sharepoint.com" -Interactive

$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
$site = Get-PnPTenantSite | Where {$_.Url -eq $SiteURL}

if ($site) {
    Write-Output "The site 'PowerShellFAQs' exists."
} else {
    Write-Output "The site 'PowerShellFAQs' does not exist."
}

นี่คือวิธีการตรวจสอบว่าไซต์ SharePoint Online มีอยู่หรือไม่ใช้ PnP PowerShell

ฉันหวังว่านี่จะช่วยได้

บทความที่เกี่ยวข้อง