Maintain control of your Microsoft 365 data
Post Reply
aschmengler
Novice
Posts: 5
Liked: 2 times
Joined: Jun 06, 2024 12:22 pm
Full Name: Ahmet Schmengler
Contact:

Licensed users without new licensed users via powershell

Post by aschmengler » 1 person likes this post

Hi,

first of all i am not very good with powershell yet, so sorry for any big mistakes, im still learning ;) Also i wasnt sure, if the 365 subforum is correct if this belongs to powershell.
I want to get the reporting done for M365 so i am checking via powershell for the used storage and users count via

Code: Select all

$users = Get-VBOLicensedUser -Organization $tenant
        $userCount = $users.Count
However when i manually compared the results to the reporting that the console offers i noticed that the number is higher because it includes the new licensed users.
As far as i understood we dont need those for the billing reporting. I didnt find a way to filter the new users out though.

shortened version of the script for context reasons:

Code: Select all

# Veeam Backup for Microsoft 365 Server
$veeamServer = "localhost"

# Vorherigen Monat und Jahr ermitteln
$previousMonth = (Get-Date).AddMonths(-1)
$previousMonthYear = $previousMonth.Year
$previousMonthMonth = $previousMonth.Month

# Den Ausgabepfad entsprechend aktualisieren
$outputDirectory = "C:\Users\Administrator\Desktop\Reports\$previousMonthYear\$previousMonthMonth"

# Überprüfen, ob der Ausgabepfad existiert, und wenn nicht, ihn erstellen
if (-not (Test-Path -Path $outputDirectory)) {
    New-Item -ItemType Directory -Path $outputDirectory | Out-Null
}

# Aktuelles Datum als Teil des Dateinamens für den HTML-Bericht
$currentDate = Get-Date -Format "yyyy_MM_dd"
$outputFile = "$outputDirectory\VeeamReport_$currentDate.html"

# Ersten und letzten Tag des vorherigen Monats berechnen
$startDate = $previousMonth.AddDays(-(Get-Date).Day + 1)
$endDate = $previousMonth.AddDays(-1)

# Verbindung zur Veeam-Instanz herstellen
try {
    Connect-VBOServer -Server $veeamServer

    # HTML-Ausgabe
    $htmlOutput = "<html><head><title>Veeam Backup for Microsoft 365 BaaS</title></head><body>"

    # Alle Tenants abrufen und alphabetisch sortieren
    $tenants = Get-VBOOrganization | Sort-Object -Property Name

    # Für jeden Tenant die gewünschten Informationen abrufen und ausgeben
    foreach ($tenant in $tenants) {
        $tenantName = $tenant.Name

        # Holen der Usage-Daten für den Tenant
        $usageData = Get-VBOUsageData -Organization $tenant

        # Speicherplatz für den aktuellen Tenant
        $usedSpace = $usageData.ObjectStorageUsedSpace

        # Überprüfen, ob $usedSpace ein Array ist und die Summe berechnen
        if ($usedSpace -is [array]) {
            $totalUsedSpace = ($usedSpace | Measure-Object -Sum).Sum
        } else {
            $totalUsedSpace = $usedSpace
        }

        # Lizenzierten Benutzer für den aktuellen Tenant abrufen
        $users = Get-VBOLicensedUser -Organization $tenant
        $userCount = $users.Count

        # Speicherplatz in GB und auf 2 Dezimalstellen abrunden
        $formattedStorageSpace = "{0:N2}" -f ($totalUsedSpace / 1GB)

        # HTML-Ausgabe für jeden Tenant erstellen
        $htmlOutput += "<h2>$tenantName</h2>"
        $htmlOutput += "<p>Anzahl der Benutzer: $userCount</p>"
        $htmlOutput += "<p>Speicherplatz: $formattedStorageSpace GB</p>"

        # Ausgabe für jeden Tenant in der Konsole
        Write-Host "Tenant: $tenantName"
        Write-Host "Anzahl der Benutzer: $userCount"
        Write-Host "Speicherplatz: $formattedStorageSpace GB"
    }

    # HTML schließen
    $htmlOutput += "</body></html>"

    # HTML in eine Datei schreiben
    $htmlOutput | Out-File -FilePath $outputFile -Encoding UTF8

    # Lizenzübersichtsbericht erstellen
    Get-VBOLicenseOverviewReport -StartTime $startDate -EndTime $endDate -Format PDF -Path $outputDirectory

    # Bericht über den Speicherverbrauch erstellen
    Get-VBOStorageConsumptionReport -StartTime $startDate -EndTime $endDate -Format PDF -Path $outputDirectory

} catch {
    # Fehlerbehandlung: Hier wird die Exception-Meldung ausgegeben, falls ein Fehler auftritt
    Write-Host "Ein Fehler ist aufgetreten: $($_.Exception.Message)"
} finally {
    # Verbindung trennen
    Disconnect-VBOServer
}
Also if there is any major flaw in this, any recommendation is appreciated.
kavaa
Enthusiast
Posts: 25
Liked: 16 times
Joined: Jan 02, 2022 10:05 am
Full Name: Kay van Aarssen
Contact:

Re: Licensed users without new licensed users via powershell

Post by kavaa »

This is a good start, we have something the same way, but also could not really figure out how to get it to match exactly.
Also what would be nice is make a split in the storage usage for files like, Sharepoint, Teams, OneDrive and Mailboxes / Shared Mailboxes
Mildur
Product Manager
Posts: 9353
Liked: 2486 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Licensed users without new licensed users via powershell

Post by Mildur »

Hello Ahmet

This subforum is ok for VB365 power shell questions. :)
Also what would be nice is make a split in the storage usage for files like, Sharepoint, Teams, OneDrive and Mailboxes / Shared Mailboxes
We don't provide such granular information. But if you use dedicated backup repositories per source type, you can get the number you are looking for.


I assume you are a Veeam service provider. The data you are looking for is also available in the Service Provider Console.
- Storage per M365 organization/VSPC company
- Licenses users per M365 organization/VSPC company

My recommendation is to use the VSPC API instead of PowerShell.
https://helpcenter.veeam.com/docs/vac/r ... gatedUsage

Code: Select all

"type": "Vb365ArchiveSize"
"type": "Vb365BackupSize"
"type": "Vb365ProtectedGroups"
"type": "Vb365ProtectedSites"
"type": "Vb365ProtectedTeams"
"type": "Vb365ProtectedUsers"
https://helpcenter.veeam.com/docs/vac/r ... ingReports

Code: Select all

{
          "organizationName": "****.onmicrosoft.com",
          "usageByLicenseAndProduct": [
            {
              "productType": "VB365",
              "usedPoints": 24,
              "workloadUsage": [
                {
                  "workloadType": "VB365_User",
                  "description": "User",
                  "initialCount": 16,
                  "reportedCount": 16,
                  "newCount": 0,
                  "weight": 1.5,
                  "usedPoints": 24,
                  "workloadsByPlatform": [
                    {
                      "typeId": "VB365-USER-M365",
                      "description": "User",
                      "objectsByWeight": [
                        {
                          "weight": 1.5,
                          "initialCount": 16,
                          "reportedCount": 16,
                          "newCount": 0,
                          "usedPoints": 24
                        }
                      ]
                    }
                  ]
                }
              }
            }
Best,
Fabian

PS:
Please register yourself in our service provider user group if you are a service provider. This gives you access to our hidden service provider sub forums where service provider products are discussed: Apply for the Cloud and Service Providers user group
Product Management Analyst @ Veeam Software
aschmengler
Novice
Posts: 5
Liked: 2 times
Joined: Jun 06, 2024 12:22 pm
Full Name: Ahmet Schmengler
Contact:

Re: Licensed users without new licensed users via powershell

Post by aschmengler »

Hello Mildur,

well i could get the storage size and the licensed users over Powershell but not filter out the new licences. But if there is no way to filter out the new uncharged licneses out then my co-worker has to solve it over API. thank you for your help!

And i will do the registration on the service provider group as well, thank you again! :)
Mildur
Product Manager
Posts: 9353
Liked: 2486 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Licensed users without new licensed users via powershell

Post by Mildur »

PowerShell is also possible. LicenseStatus provides the status of the assigned license:
- New: New users in the trial month, doesn't need to be reported
- Licensed: Users which are fully licensed and needs to be reported

You can use this filter to query only licensed users:

Code: Select all

$users = Get-VBOLicensedUser -Organization $tenant | Where-Object {$_.LicenseStatus -eq 'Licensed'}
$userCount = $users.Count
I still recommend to check out the VSPC API and it's capabilities :) It was build for Service Providers and let you query information for all connected backup server, not just one.

Best,
Fabian
Product Management Analyst @ Veeam Software
Post Reply

Who is online

Users browsing this forum: No registered users and 99 guests