From 5ce39ff8e4ee69895c989d0ffedc97125e68d570 Mon Sep 17 00:00:00 2001 From: dracon80 Date: Mon, 11 Jul 2022 12:01:06 +1000 Subject: [PATCH] Using TenantID rather then default domain --- .gitignore | 2 ++ Exec-HuduM365ProcessTenant/run.ps1 | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 4563a76..2c7e4d2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ bin obj appsettings.json local.settings.json +scratch.ps1 +Test-ProcessTenant/* # Azurite artifacts __blobstorage__ diff --git a/Exec-HuduM365ProcessTenant/run.ps1 b/Exec-HuduM365ProcessTenant/run.ps1 index 283e92a..47cca76 100644 --- a/Exec-HuduM365ProcessTenant/run.ps1 +++ b/Exec-HuduM365ProcessTenant/run.ps1 @@ -35,14 +35,14 @@ $EnableCIPP = [System.Convert]::ToBoolean($env:EnableCIPP) $CIPPURL = $env:CIPPURL try { - $hududomain = Get-HuduWebsites -name "https://$defaultdomain" -ea stop - $domaincount = ($hududomain.id | measure-object).count + $huduAPIAsset = Get-HuduAssets -Name $Customer.customerId -ea stop - if ($domaincount -eq 1) { + if ($null -ne $huduAPIAsset){ $TenantFilter = $Customer.CustomerId - $company_name = $hududomain[0].company_name - $company_id = $hududomain[0].company_id + $company_name = $huduAPIAsset.company_name + $company_id = $huduAPIAsset.company_id + $ExchangeAuthenticated = $true try { @@ -930,11 +930,11 @@ try { } catch { $CompanyResult.Errors.add("Company: Failed to import domain: $_") } - - } elseif ($domaincount -eq 0) { - $CompanyResult.Errors.add("Company: Domain not found in Hudu please add $defaultdomain to a company") + + } elseif ($null -eq $huduAPIAsset) { + $CompanyResult.Errors.add("Company: API Asset not found in Hudu please add $($Customer.customerId) to a company") } else { - $CompanyResult.Errors.add("Company: Multiple companies matched in Hudu for $defaultdomain") + $CompanyResult.Errors.add("Company: Multiple companies matched in Hudu for $($Customer.customerId)") } } catch { $CompanyResult.Errors.add("Company: A fatal error occured: $_")