Maintain control of your Microsoft 365 data
Post Reply
ronaldw
Novice
Posts: 7
Liked: 1 time
Joined: Oct 01, 2014 11:57 am
Full Name: ronald w
Contact:

Matching VBOEntityData with VBOLicensedUser

Post by ronaldw »

Get-VBOEntityData gives back members: Displayname, Email
Get-VBOLicensedUser gives back members, Username, OfficeId

I have users which have a different Username then their E-mail.

I'd like to match if users which i find in Get-VBOEntityData have a license yes or no, with a 100% definite match.
The most clean would be, that Get-VBOEntityData would also give back OfficeId

I've checked several cmdlets to make this match possible.


below is my ultimate attempt to make this match happen. but the data still is inconsistent.
How can i make this match in a decent way ?

It should be possible, that for every user which is found in the licenses, we can 100% prove there is a backup.

Code: Select all

Import-Module Veeam.Archiver.PowerShell

$storage = Get-VBORepository
$organizations = Get-VBOOrganization
$alljobs = Get-VBOJob

$dateverbose = get-date -date $(get-date).addmonths(-1)
$lastDay = [DateTime]::DaysInMonth($dateverbose.Year, $dateverbose.Month)
$firstDate = [DateTime]::new($dateverbose.Year, $dateverbose.Month, 1)
$lastDate = [DateTime]::new($dateverbose.Year, $dateverbose.Month, $lastDay)

$existtemp = test-path -path 'c:\temp'
if (!($existtemp)) { New-Item -ItemType "directory" -Path 'c:\temp' | Out-Null }

#Can only be done to a file. Get-VBOLicensedUser gives incomplete data. Therefor this ugly workaround.
Get-VBOLicenseOverviewReport -StartTime $firstDate -EndTime $lastDate -path c:\temp -Format CSV
$csvfile = Get-Childitem -Path C:\temp -Include *Veeam_LicenseOverviewReport* -Recurse -ErrorAction SilentlyContinue
$csvdata = import-csv -Path $csvfile
remove-item $csvfile

$Audit = @()

foreach ($org in $organizations) {

    $jobs = $alljobs | where-object { $_.Organization.name -eq $org.Name }
    $repositories = @()
    foreach ($job in $jobs) {
        $repositories += $storage | where-object { $_.id -eq $job.Repository.id }
    }
    $repositories = $repositories | sort-object Id -Unique

    foreach ($repo in $repositories) {

        $backupdata = $repo | Get-VBOEntityData -type user
        $users = Get-VBOOrganizationUser -Organization $org
        $licenses = $csvdata | where-object { $_.Organization -eq $org.name }
     
        foreach ($backup in $backupdata) {
            $user = $users | where-object { $_.Username -eq $backup.email }
            if (!$user) {
                $user = $users | where-object { $_.DisplayName -eq $backup.DisplayName }
          
            }

            if ($user.count -gt 1) {
                if ($backup.email) {
                    $usersearch = $backup.Email.split('@') | select -last 1
                    $test = $user | where-object { $_.username -match $usersearch }
                    if ($test.count -eq 1) {
                        $user = $test
                    }
                }
            }
            if ($username) { Remove-Variable username }

            if ($user.count -gt 1) {
                $username = $backup.Email
                $user = $user | select -first 1
            }

            if (!$username) {
                if ($user) {
                    $username = $user.username
                }
                else {
                    $username = $backup.Email
                }
            }
            if ($note) { Remove-Variable note }
            if (!$username) {
                $username = 'Unknown'
                $note = 'e-mail adres is onbekend in de backup. Ook niet gevonden in de licentie aangezien die er niet is'
            }


            $lic = $licenses | where-object { $_.'Account name' -eq $user.UserName }
            if (!$lic) {
                $lic = $licenses | where-object { $_.'Account name' -eq $backup.Email }
            }

            if ($user) { $useractive = $true } else { $useractive = $false }
            if ($lic) { $licenseactive = $true } else { $licenseactive = $false }

            $dates = @()
            $dates += $backup.MailboxBackedUpTime
            $dates += $backup.OneDriveBackedUpTime
            $dates += $backup.PersonalSiteBackedUpTime
            $dates += $backup.ArchiveBackedUpTime

            if ($lastseen) { Remove-Variable lastseen }
            if ($timedelta) { Remove-Variable timedelta }
            try { $lastseen = $(get-date $($dates | sort-object -Descending | select -first 1)) } catch {}
            if ($lastseen) {
                $timedelta = $(get-date) - $(get-date $lastseen)
            }
        
            if ($type) { remove-variable type }
            if ($user -and $lic) { $type = 'User' }

            if (!$user -and $lic -and $timedelta.TotalDays -gt 7) {
                $type = 'History'
            }

            if (!$user -and !$lic) {
                $type = 'History'
            }

            if ($user -and !$lic -and $timedelta.TotalDays -lt 7) {
                $type = 'SharedMailbox'
            }
        
            if ($user -and !$lic -and $timedelta.TotalDays -gt 7) {
                $type = 'History'
            }

            if (!$type) { $type = 'Unknown' }


            $obj = @{
                Email          = $backup.Email
                DisplayName    = $backup.DisplayName
                Username       = $username
                licusername    = $lic.'Account name'
                Organization   = $Backup.Organization.DisplayName
                OrgId          = $org.id
                Repo           = $repo.Name
                useractive     = $useractive
                licenseactive  = $licenseactive
                licenseisTrial = $lic.'Is Trial'
                BackupMailbox  = $backup.IsMailboxBackedUp
                ArchiveBackup  = $backup.IsArchiveBackedUp
                SiteBackup     = $backup.IsPersonalSiteBackedUp
                OnedriveBackup = $backup.IsOneDriveBackedUp
                lastSeen       = $lastSeen
                Type           = $type
                Notitie        = $note
            }
            $Audit += $obj

        }
    }

}
Mildur
Product Manager
Posts: 9848
Liked: 2609 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Matching VBOEntityData with VBOLicensedUser

Post by Mildur »

Hello Ronald

May I ask why you require this comparison/proof? For your management?

Maybe Veeam One can solve your use case? Veeam One is completely free for Veeam backup for Microsoft 365.
In Veeam One we have a Report called "Protected Objects". You can specify your own RPO period and generate a report for:
- objects in your targeted RPO period
- objects which have missed the RPO period
- objects do not have any backup at all

https://helpcenter.veeam.com/docs/one/r ... ml?ver=120

Best,
Fabian
Product Management Analyst @ Veeam Software
ronaldw
Novice
Posts: 7
Liked: 1 time
Joined: Oct 01, 2014 11:57 am
Full Name: ronald w
Contact:

Re: Matching VBOEntityData with VBOLicensedUser

Post by ronaldw »

This is indeed for our management, but also for ourselves.
I don't want to use Veeam One, as we (always ;)) have very specific needs for accounting.
My goal is to create a one to one relation to our invoicing system.

I already have that, because i can retreive the licenses used in several periods etc.

but, we can restore like 15000 mailboxes. but we only have 10000 licenses.
A lot of old mailboxes. Shared mailboxes without a license.

"which ones don't have a license then"

This would really help me :)
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests