Private/Curanet/M365/Connect-CuranetM365API.ps1
function Connect-CuranetM365API() { param( [Parameter(Mandatory)] [string] $CustomerId) $M365Subscription = Get-CuranetCustomerSubscriptions -Account 3850 -CustomerId $CustomerId | Where-Object { $_.type -eq "Microsoft 365 (Indirect Reseller)"} if(!$Global:CuranetM365APIToken -or $Global:CuranetM365APIToken.subScriptionId -ne $M365Subscription.ID -or $Global:CuranetM365APIToken.expirationDateTime -lt (Get-Date)) { $Global:CuranetM365APIToken = $null $CuranetM365APIToken = Get-DecodedJWT -Token (Get-CuranetM365APIToken -SubscriptionId $M365Subscription.ID) } if(!$CuranetM365APIToken) { throw "Failed to get M365 API token" } $Global:CuranetM365APIToken = $CuranetM365APIToken } |