microsoft / Partner-Center-PowerShell

PowerShell module for managing Partner Center resources.
https://docs.microsoft.com/powershell/partnercenter/
MIT License
130 stars 59 forks source link

Cannot get tenant subscription list if tenant has an expired subsctiption. #394

Open DavidMoore-intY opened 2 years ago

DavidMoore-intY commented 2 years ago

Steps to reproduce

Run 'Get-PartnerCustomerSubscription' against a tenant with an expired subscription

Expected behavior

List of subscriptions on the tenant is returned

Actual behavior

Get-PartnerCustomerSubscription : Requested value 'Expired' was not found. At line:1 char:2

Diagnostic logs

Running with -debug shows data being returned from Microsoft as expected. Logs not included as it is a live customer tenant.

Environment

PSVersion 5.1.18362.1801
PSEdition Desktop

ModuleType Version Name


Script 3.0.10 PartnerCenter

aunCoreyGood commented 2 years ago

Having this exact issue as well. Suspending the subscription doesn't seem to fix this and I'm unable to cancel the expired subscription.

DavidMoore-intY commented 2 years ago

@aunCoreyGood I've ended up implementing the calls I need myself as separate functions

Function Get-MSCustomerSubscriptions {

    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [GUID]$TenantID
    )

    $result = (Invoke-RestMethod -Method GET -URI "https://api.partnercenter.microsoft.com/v1/customers/$TenantID/subscriptions" -Authentication Bearer -Token Get-MSAccessToken)

    Return $Result.items

}

Get-MSAccessToken is specific to my environment, but once you've implemented a way to get a token all the rest is fairly easy.

DavidMoore-intY commented 2 years ago

On a similar note, the BillingCycle 'Triennial' isn't supported by the powershell module so anything that involves getting details of a product that supports that billing type will fail.

TheSTHDK commented 2 years ago

Having the same issue. The Expired subscription is showing in the Debug output, but the module does not know how to handle the expired status it seems. I will try your workaround David.

mwasham commented 1 year ago

Any chance this is going to get fixed soon?

ezcodify commented 1 year ago

Any chance this is going to get fixed soon?

I sure hope so - I have this issue as well

despian commented 1 year ago

Also encountered this. David's workaround works well though. Thanks.

If anyone needs a token for unattended access:

$token = (New-PartnerAccessToken `
  -ApplicationId $pcClientId `
  -Credential $pcCreds `
  -Scopes "https://graph.windows.net/.default" `
  -ServicePrincipal `
  -Tenant $pcTenantId).AccessToken
[securestring]$ssToken = ConvertTo-SecureString $token -AsPlainText -Force
ngailloux-softlanding commented 8 months ago

I can't believe this is still an open issue almost two years on. We are also seeing this same issue if any subscriptions are in the "Disabled" state, or if the BillingCycle is "Triennial". This is causnig us to not be able to do a full subscription export via PowerShell.

DavidMoore-intY commented 8 months ago

@ngailloux-softlanding Last release was 3 and a half years ago, I think it's pretty clear that this module has been abandoned now. Unfortuantely Microsoft's documentation still directs people to it in quite a few places.

I've ended up building a module with all the functionality we need myself, once you've set up the necessary stuff for authentication the majority of the calls are very straightforward to implement.

mprentice22153 commented 8 months ago

As @DavidMoore-intY said, the PartnerCenter module is abandoned. It would be best to switch to using the APIs and modernizing your scripts. You will find more fields available to you and also not encounter the broken functionality described here and elsewhere. The New-PartnerAccessToken cmdlet was the last one I held onto from the old module but now have a replacement for that using APIs.

This is unfair of me to say: I would share with you what I have created but for now I'm too buried with projects to spend time cleaning up my code so I'm comfortable sharing it. Over a year ago I started with getting authentication working, then I've built my own module of customer functions to replace the old module. As necessary I add a new function and keep moving on. As @DavidMoore-intY said, most are straightforward to implement.