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
}
}
}