Apr 03 2023 12:27 PM - edited Apr 03 2023 12:30 PM
From an admin standpoint how could you manage cost centers / cost allocation to SharePoint Online Farm? Would be ideal to add a custom column in the SharePoint admin center to the sites so that cost can be managed per business unit and when needing to purchase more space to cost allocate. Is this possible with any other tools Microsoft has such as SharePoint Syntax or Azure Purview? Thank you.
Apr 04 2023 04:53 AM
Apr 04 2023 08:06 AM
Apr 04 2023 12:45 PM
Apr 04 2023 12:51 PM
Apr 04 2023 01:37 PM - edited Apr 04 2023 01:40 PM
Yes and no!
So Microsoft won't make that change, I know several people for large organisations that have tried and gotten denied. Azure Purview and SharePoint Syntax don't have the possibility to to get this information.
So the option is to build something yourself or buy, Luckily it's pretty simple do build.
1. If your AD is up to date and proper department and you don't have orphaned sites etc.:
So first you need a script that get's all the sites and it's get's the owner. And then you do a lookup to the owner to see the department. Here's a script I created that you can use:
# This PowerShell script will get all SharePoint Online sites, their data usage, their owner and department of the owner and export the results to a CSV file.
# Load SharePoint Online Management Shell
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
# Connect to SharePoint Online Admin Center
Connect-SPOService -Url https://contoso-admin.sharepoint.com
# Get all site collections
$Sites = Get-SPOSite -Limit All
# Create an empty array to store the results
$Results = @()
# Loop through each site collection
foreach ($Site in $Sites) {
# Get the site URL, data usage and owner
$SiteUrl = $Site.Url
$SiteUsage = $Site.StorageUsageCurrent
$SiteOwner = $Site.Owner
# Get the owner's department from Azure AD
$Owner = Get-AzureADUser -ObjectId $SiteOwner
$OwnerDepartment = $Owner.Department
# Create a custom object with the properties
$Result = [PSCustomObject]@{
SiteUrl = $SiteUrl
SiteUsage = $SiteUsage
SiteOwner = $SiteOwner
OwnerDepartment = $OwnerDepartment
}
# Add the object to the array
$Results += $Result
}
# Export the array to a CSV file
$Results | Export-Csv -Path "C:\Temp\Sites.csv" -NoTypeInformation
2. If the AD isn't properly (aka department isn't tagged)
Then follow my previous post. This tags the site in-case the owner quits, orphaned sites etc. (reason I wrote it first)
Apr 04 2023 02:21 PM
Apr 06 2023 08:25 AM
Apr 06 2023 03:55 PM - edited Apr 07 2023 03:54 AM
$SiteOwner is empty, so your Site proabably doesn't have any owner. You need to do add a check for that 🙂
Side note: Always make sure to have two owners on all sites/group. This is best practice
Apr 07 2023 08:23 AM
Apr 08 2023 10:02 AM
This will get M365 groups. I'll have you try to see what you need to merge between this and previous script to get the output you want Ping me if you get stuck
# Define the output file path
$OutputFile = "C:\temp\M365Groups.csv"
# Get all M365 groups
$Groups = Get-MgGroup -All
# Create an empty array to store the results
$Results = @()
# Loop through each group
foreach ($Group in $Groups) {
# Get the group owner
$Owner = Get-MgGroupOwner -GroupId $Group.Id
# Create a custom object with the group and owner details
$Object = [PSCustomObject]@{
"Group Name" = $Group.DisplayName
"Group Email" = $Group.Mail
"Group Type" = $Group.GroupTypes -join ", "
"Owner Name" = $Owner.DisplayName
"Owner Email" = $Owner.Mail
}
# Add the object to the results array
$Results += $Object
}
# Export the results to a CSV file
$Results | Export-Csv -Path $OutputFile -NoTypeInformation
# Write a message to indicate the script is done
Write-Host "The script has completed. The output file is located at $OutputFile