Public/PartnerActions/Get-Tenants.ps1
function Get-Tenants { Param( [Parameter()] [string]$TenantId, [Parameter()] [string]$DefaultDomainName, [Parameter()] [string]$SearchString ) process { Connect-CustomerGraph -CustomerTenantId $PartnerTenantId try { $Customers = Get-MgContract -All -ErrorAction Stop if($SearchString) { $Customers = $Customers | Where-Object { $_.DisplayName -like "*$($SearchString)*" -or $_.DefaultDomainName -like "*$($SearchString)*" } } else { if($TenantId) { $Customers = $Customers | Where-Object { $_.CustomerId -eq $TenantId } } elseif ($DefaultDomainName) { $Customers = $Customers | Where-Object { $_.DefaultDomainName -like "*$($DefaultDomainName)*" } } } $Customers } catch { throw "Failed to retreive customers from MS Graph: $_" } } } |