Public/TenantConfiguration/Export/Export-TenantUserList.ps1
function Export-TenantUserList() { param( [Parameter(Mandatory)] [string]$TenantId ) Connect-CustomerGraph -CustomerTenantId $TenantId $Domains = Get-MgDomain -All $CuranetSubscriptions = Get-CuranetCustomerSubscriptions -Account 3850 foreach($Domain in $Domains) { $MatchingCuranetSubscription = $CuranetSubscriptions | Where-Object {$_.description -eq $Domain.Id} | Select-Object -First 1 if($MatchingCuranetSubscription) { break } } if($MatchingCuranetSubscription) { $CuranetCustomer = Get-CuranetCustomer -Account 3850 -CustomerId $MatchingCuranetSubscription.customerId $MatchChoice = Read-Host "Found matching Curanet customer $($CuranetCustomer.companyName). Does this seem correct? [y/n]" } if(!$MatchingCuranetSubscription -or $MatchChoice.ToLower() -eq 'n)') { $KL = Read-Host "Please enter the KL number for the customer" -ForegroundColor Cyan $MatchingCuranetSubscription = $CuranetSubscriptions | Where-Object {$_.subscriptionRef -eq $KL} | Select-Object -First 1 $CuranetCustomer = Get-CuranetCustomer -Account 3850 -CustomerId $MatchingCuranetSubscription.customerId } if(!$CuranetCustomer) { throw "Failed to find Curanet customer, customer must not have KL number set in Curanet" } try { Write-Host "Retreiving users.." -ForegroundColor Cyan $TenantUsers = Get-CuranetM365Users -CustomerId $CuranetCustomer.id Write-Host "Retreiving subscriptions.." -ForegroundColor Cyan $TenantSubscriptions = Get-CuranetM365TenantSubscriptions -CustomerId $CuranetCustomer.id Write-Host "Retreiving backup status.." -ForegroundColor Cyan $BackupStatus = Get-CuranetM365BackupStatus -CustomerId $CuranetCustomer.id } catch { throw "Failed to get M365 users or subscriptions: $_" } foreach($User in $TenantUsers) { Write-Host "ID: $($User.id)" Write-Host "displayName: $($User.displayName)" } foreach($TenantSubscription in $TenantSubscriptions) { Write-Host "Name: $($TenantSubscription.friendlyName)" Write-Host "Quantity: $($TenantSubscription.quantity)" Write-Host "Creation date: $($TenantSubscription.creationDate)" } } |