
9,747 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi there
For SharePoint Online:
What PowerShell can output a CSV file with a list of ALL site collections in our SP Online along with:
Thank you.
Hello Frob,
Thank you for your question and for reaching out with your question today.
To retrieve a CSV file with a list of all site collections in SharePoint Online along with site collection owners and the number of visits in the last 90 days, you can use the SharePoint Online Management Shell module and PowerShell. Here's an example PowerShell script:
# Connect to SharePoint Online
Connect-SPOService -Url "
# Get all site collections
$siteCollections = Get-SPOSite
# Create an array to store site collection data
$siteCollectionData = @()
# Iterate through each site collection
foreach ($siteCollection in $siteCollections) {
# Get site collection owners
$owners = Get-SPOUser -Site $siteCollection.Url -Role "Full Control" | Select-Object -ExpandProperty LoginName
# Get number of visits in the last 90 days
$analytics = Get-SPOAnalyticsSiteUsageData -SiteUrl $siteCollection.Url -StartDate (Get-Date).AddDays(-90) -EndDate (Get-Date)
$visits = $analytics.Usage | Measure-Object -Property Views -Sum | Select-Object -ExpandProperty Sum
# Create an object with site collection data
$siteCollectionData += [PSCustomObject]@{
"Site Collection URL" = $siteCollection.Url
"Site Collection Owners" = $owners -join ";"
"Number of Visits (Last 90 Days)" = $visits
}
}
# Export the site collection data to a CSV file
$siteCollectionData | Export-Csv -Path "C:\Path\to\output.csv" -
Make sure to replace `"
When you run the script, it will connect to SharePoint Online, retrieve information for each site collection, and save the data to a CSV file with the specified columns: Site Collection URL, Site Collection Owners, and Number of Visits (Last 90 Days).
I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.
If the reply was helpful, please don’t forget to upvote or accept as answer.
Best regards.