Tìm kiếm trang web

SharePoint Online: Nhận tất cả tuyển tập trang bằng PowerShell


Yêu cầu: Tải tất cả tuyển tập trang bằng PowerShell trong SharePoint Online.

Làm cách nào để có được danh sách tuyển tập trang trong SharePoint Online?

Tuyển tập trang là một nhóm các trang, thường được tổ chức theo bộ phận, dự án, khu vực, chức năng hoặc đơn vị kinh doanh. Nếu bạn chịu trách nhiệm quản lý môi trường SharePoint Online thì sớm hay muộn bạn cũng sẽ cần có danh sách tất cả các tuyển tập trang trong hợp đồng thuê của mình. Rất may, PowerShell giúp việc thu thập thông tin về môi trường SharePoint Online của bạn trở nên dễ dàng. Bài đăng blog này sẽ chỉ cho bạn cách sử dụng PowerShell để lấy danh sách tất cả các tuyển tập trang trong đối tượng thuê của bạn. Bạn cũng sẽ tìm hiểu cách xuất kết quả thành tệp CSV hoặc HTML cho mục đích báo cáo.

Xem tất cả các trang trong SharePoint Online Người thuê bằng Trung tâm quản trị SharePoint

Làm cách nào để xem tất cả các tuyển tập trang trong SharePoint Online? Chà, nếu bạn muốn lấy danh sách các bộ sưu tập trang SharePoint Online, bạn có thể truy cập trung tâm quản trị SharePoint (https://YourDomain-admin.sharepoint.com) >> Mở rộng “Trang web” > > Trang web đang hoạt động.

Điều này sẽ giúp bạn có được danh sách tất cả các tuyển tập trang trong SharePoint Online. Bạn có thể xuất chúng sang CSV bằng cách nhấp vào nút “Xuất” trên thanh công cụ. Hãy xem SharePoint Online PowerShell để có được tất cả các tuyển tập trang.

Làm cách nào để có được Bộ sưu tập Trang web trong SharePoint Online bằng PowerShell?

Với tư cách là quản trị viên SharePoint Online, bạn cần truy xuất thông tin về một tuyển tập trang cụ thể trong môi trường SharePoint của mình. Để có được tuyển tập trang trong SharePoint Online bằng PowerShell, bạn có thể làm theo các bước sau:

  1. Mở PowerShell trên máy cục bộ của bạn.
  2. Kết nối với đối tượng thuê SharePoint Online của bạn bằng lệnh ghép ngắn Connect-SPOService. Bạn sẽ cần cung cấp URL và thông tin xác thực của quản trị viên SharePoint Online.
  3. Chạy lệnh ghép ngắn Get-SPOSite để truy xuất tuyển tập trang mà bạn muốn. Ví dụ: để truy xuất tuyển tập trang web có URL “https://crescent.sharepoint.com/sites/marketing”, bạn sẽ chạy lệnh sau: Get-SPOSite -Identity https://crescent.sharepoint. com/sites/marketing Điều này sẽ trả về thông tin về tuyển tập trang web, bao gồm URL, tiêu đề và chủ sở hữu của nó.
  4. Nếu bạn muốn truy xuất thông tin bổ sung về tuyển tập trang, bạn có thể sử dụng các lệnh ghép ngắn PowerShell khác, chẳng hạn như Get-SPOSiteGroup hoặc Get-SPOSiteGroupPermissions.

#Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"

#Connect to SharePoint Online from PowerShell
Connect-SPOService -url $AdminSiteURL

#Get the Site Collection
$Site =  Get-SPOSite -Identity $SiteURL

#sharepoint online list all site collections powershell
$Site | Select -Property Template, StorageUsageCurrent, StorageQuota, LastContentModifiedDate, sharingcapability

Xin lưu ý, Để chạy lệnh ghép ngắn PowerShell cho SharePoint Online, bạn cần có vai trò Quản trị viên SharePoint trên đối tượng thuê và SharePoint Online Management Shell (hoặc mô-đun SharePoint Online PowerShell) được cài đặt trên máy cục bộ của bạn.

Làm cách nào để có được tất cả tuyển tập trang trong SharePoint Online bằng PowerShell?

Tuyển tập trang là đối tượng chính trong SharePoint Online. Sử dụng lệnh ghép ngắn Get-SPOSite PowerShell để liệt kê tất cả các tuyển tập trang trong đối tượng thuê. Tương tự như SharePoint Management Shell tại chỗ, Bạn cũng có thể sử dụng “SharePoint Online Management Shell” để kết nối với các trang Office 365 và SharePoint Online! Đây là tập lệnh PowerShell để tải tất cả tuyển tập trang trong SharePoint Online:


Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

$AdminSiteURL="https://crescent-admin.sharepoint.com"

$Credential = Get-credential 
Connect-SPOService -url $AdminSiteURL -Credential $Credential 

#sharepoint online list all site collections powershell
Get-SPOSite -Limit All | Format-Table Url, Template, StorageUsageCurrent, StorageQuota, LastContentModifiedDate, sharingcapability -AutoSize 

Theo mặc định, lệnh ghép ngắn Get-SPOSite truy xuất 200 tuyển tập trang. Chúng ta phải chỉ định nút chuyển “Giới hạn” bằng “Tất cả” để lấy tất cả các trang web từ đối tượng thuê. Đây là tập lệnh PowerShell để lấy tất cả các tuyển tập trang web với thông tin chi tiết từ SharePoint Online và Xuất tất cả khoảng không quảng cáo của Tuyển tập trang sang CSV:


Connect-SPOService -url "https://crescent-admin.sharepoint.com" -Credential (Get-credential)
Get-SPOSite -Detailed | Export-CSV -LiteralPath C:\Temp\SitesInventory.csv -NoTypeInformation

PowerShell này liệt kê tất cả các tuyển tập trang trong đối tượng thuê SharePoint Online cùng với tất cả các chi tiết có sẵn của tuyển tập trang.

PowerShell để tải tất cả tuyển tập trang web trong SharePoint Online

Làm cách nào để kết nối với SharePoint Online bằng thông tin đăng nhập đã lưu? Đây là PowerShell để liệt kê tất cả các trang SharePoint Online sử dụng thông tin xác thực đã lưu (Tôi giả sử tài khoản bạn chỉ định trong tập lệnh chưa bật MFA!):


#Load SharePoint Online Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Variables for Processing
$AdminUrl = "https://crescent-admin.sharepoint.com/"
$UserName= "Salaudeen@crescent.com"
$Password = "Password goes here"
 
#Setup Credentials to connect
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword

#connect to the service
Connect-SPOService -Url $AdminUrl -Credential $Credentials

#sharepoint online get all site collections PowerShell
$SiteColl = Get-SPOSite 

#sharepoint online PowerShell iterate through all site collections
ForEach($Site in $SiteColl)
{
    Write-host $Site.Url
}

PowerShell để có được tất cả các tuyển tập trang web, bao gồm các trang web nhóm hiện đại và trang web nhóm:

PowerShell này liệt kê các tuyển tập trang trong SharePoint Online và lấy URL cho từng trang.

Hãy lấy danh sách tất cả các trang, bao gồm các trang nhóm Hiện đại và các trang được kết nối nhóm trong SharePoint Online bằng PowerShell.


#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"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"
  
#Get All Site collections from the Tenant- Including Modern Team sites and communication sites
Function Get-SPOSites($AdminSiteURL, $Cred)
{
    #Setup credentials to connect
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
   
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
    $Ctx.Credentials = $Credentials
  
    #Get the tenant object 
    $Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($ctx)
  
    #Get All Site Collections
    $SiteCollections=$Tenant.GetSitePropertiesFromSharePoint(0,$true)
    $Ctx.Load($SiteCollections)
    $Ctx.ExecuteQuery()
 
    #Iterate through Each site collection
    ForEach($Site in $SiteCollections)
    {
        Write-host $Site.URL
    }
}
  
#Set Parameters
$AdminSiteUrl = "https://crescent-admin.sharepoint.com/"
$Cred= Get-Credential

#sharepoint online powershell list all sites
Get-SPOSites -AdminSiteURL $AdminSiteUrl -Cred $Cred

SharePoint Online PowerShell để liệt kê tất cả tuyển tập trang

Hãy lấy tất cả các tuyển tập trang theo một đường dẫn cụ thể:


Import-Module Microsoft.Online.SharePoint.Powershell

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"

#Get Credentials to connect to the SharePoint Admin Center
$Cred = Get-Credential

#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -Credential $Cred

#Get All site collections which has /sites in its path
Get-SPOSite -Filter { Url -like '*/sites*' } -Limit All

#Get All site collections of Group site template
#Get-SPOSite -Filter { Template -eq "GROUP#0" } -Limit All

Bạn có thể lọc và lấy tất cả tuyển tập trang dựa trên một số tiêu chí. Ví dụ: hãy lấy tất cả các trang web đang sử dụng bộ nhớ> 1 GB.


Get-SPOSite -Limit All | where { $_.StorageUsageCurrent -gt 1024 }

Để lọc và nhận các bộ sưu tập: Ví dụ: lấy tất cả các bộ sưu tập trang web có “Dự án*” trong URL của chúng.


Get-SPOSite -Filter {$_.url -like "https://tenant.sharepoint.com/sites/Project*"}

SharePoint Online PnP PowerShell để có được tất cả các trang web

Bạn cần có danh sách tất cả các tuyển tập trang trong môi trường SharePoint Online của mình? PnP PowerShell để giải cứu! Tập lệnh này chỉ cho bạn cách sử dụng lệnh ghép ngắn PnP PowerShell Get-PnPTenantSite để nhận danh sách tất cả các tuyển tập trang trong đối tượng thuê của bạn.


#Set Parameter
$TenantSiteURL="https://crescent.sharepoint.com"

#Connect to the Tenant site
Connect-PnPOnline $TenantSiteURL -Credentials (Get-Credential)

#sharepoint online pnp powershell get all sites
Get-PnPTenantSite

Chúng tôi có thể trích xuất tất cả chi tiết về bộ sưu tập trang web và xuất chúng sang CSV bằng cách sử dụng như sau:


#Config Variables
$TenantSiteURL =  "https://crescent-admin.sharepoint.com/"
$CSVFilePath = "C:\Temp\AllSitesData.csv"

#Connect to Tenant Admin Site
Connect-PnPOnline -Url $TenantSiteURL -Interactive

#Get All Site collections data and export to CSV
Get-PnPTenantSite -Detailed | Select Title, URL, Owner, LastContentModifiedDate, WebsCount, Template, StorageUsage | Export-Csv -path $CSVFilePath -NoTypeInformation

Điều này sẽ nhận được tất cả các tuyển tập trang, bao gồm các trang nhóm hiện đại và các trang liên lạc. Hãy bỏ qua trung tâm tìm kiếm, Máy chủ trang web của tôi, Danh mục ứng dụng, Trung tâm loại nội dung, Khám phá điện tử và Bot, v.v. và nhận hạn ngạch của tất cả các trang web trong đối tượng thuê:


#Parameter
$TenantAdminURL = "https://Crescent-admin.sharepoint.com"

#Connect to Admin Center
Connect-PnPOnline -Url $TenantAdminURL -Interactive
   
#Get All Site collections - Exclude: Seach Center, Redirect site, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bot Sites
$SiteCollections = Get-PnPTenantSite | Where -Property Template -NotIn ("SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")
   
#Loop through each site collection
ForEach($Site in $SiteCollections)
{
    #Get the storage Quota of the site
    Write-host $Site.URL - $Site.StorageQuota
}

Bạn có thể bao gồm các trang OneDrive dưới dạng:


#Get all site collections including OneDrive Sites
Get-PnPTenantSite -IncludeOneDriveSites

Nhận Danh sách Tuyển tập Trang web ở định dạng Báo cáo HTML

Hãy lấy danh sách tất cả các bộ sưu tập trang web ở định dạng HTML thân thiện bằng PowerShell:


Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput="C:\Temp\SitesRpt.html"

#CSS Styles
$HeadTag = @"
<style type="text/css">

table {
 border-collapse: collapse; font-family: verdana,arial,sans-serif;
 font-size:11px; color:#333333; border-width: 1px; border-color: #a9c6c9;
 border: b1a0c7 0.5pt solid; border-spacing: 1px; border-collapse: separate; /*Sal Table format */  
}

th {
border-width: 1px; padding: 5px; background-color:#8064a2;
border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; 
color: white;  font-size: 11pt;  font-weight: 700;  text-decoration: none;
}

td {
 border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; color: black; 
 font-size: 11pt; font-weight: 400; text-decoration: none; 
}

tr:nth-child(even) { background-color: #e4dfec; }
tr:hover { background-color: #694D8C; color:#ffffff }

</style>
"@

$PreContentTag = "<h3> SharePoint Online: Site Collections Inventory Report </h3>"

#Get Credentials to connect to the SharePoint Admin Center
$Cred = Get-Credential

#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

#Get the site collection details, convert to html and output to the report
$SiteCollections | ConvertTo-HTML -Title "Site Collection Inventory Report" -Property URL, Title,@{Expression={$_.LastContentModifiedDate }; Label="Last Modified"} -Head $HeadTag -PreContent $PreContentTag | Out-File $ReportOutput

Và báo cáo trông như thế này:

Kết thúc

Tóm lại, PowerShell cung cấp một cách mạnh mẽ và hiệu quả để truy xuất danh sách tất cả các tuyển tập trang trong SharePoint Online. Bằng cách sử dụng các lệnh ghép ngắn PowerShell thích hợp, quản trị viên SharePoint có thể truy xuất danh sách toàn diện về tất cả các tuyển tập trang trong môi trường của họ một cách nhanh chóng và dễ dàng. Thông tin này có thể được sử dụng cho nhiều nhiệm vụ quản lý và kiểm tra khác nhau, chẳng hạn như kiểm tra, khắc phục sự cố, theo dõi việc sử dụng và tối ưu hóa môi trường SharePoint.

Đây là một bài viết khác về cách sử dụng PowerShell với SharePoint Online: Cách sử dụng PowerShell với SharePoint Online?

Các câu hỏi thường gặp:

Làm cách nào để tạo bộ sưu tập trang SharePoint Online bằng PowerShell?

Bạn có thể tạo các trang mới trong SharePoint Online bằng cách sử dụng SharePoint Online Management Shell - lệnh ghép ngắn New-SPOSite, PnP PowerShell New-PnPTenantSite hoặc tập lệnh CSOM PowerShell.
Thông tin thêm: PowerShell để tạo tuyển tập trang mới trong SharePoint Online

Làm cách nào để có được tất cả các trang con trong SharePoint Online bằng PowerShell?

Để có được tất cả các site con từ một site SharePoint Online, hãy sử dụng: lệnh ghép ngắn Get-PnPSubWeb trong PnP PowerShell. Bạn cũng có thể sử dụng tập lệnh CSOM PowerShell để tải các trang web (trang con) của một tuyển tập trang.
Thông tin thêm: PowerShell để lấy tất cả các trang con trong tuyển tập trang trong SharePoint Online

Làm cách nào để có được tất cả các trang SharePoint và trang con trong PowerShell?

Để có được tất cả các tuyển tập trang và các trang con, Bạn phải lấy bộ sưu tập web theo cách đệ quy trong CSOM. Với PnP PowerShell: Get-PnPSubWeb -Recurse
Thông tin thêm: PowerShell để lấy tất cả các tuyển tập trang và trang con trong SharePoint Online

Bài viết liên quan