microsoft / Partner-Center-PowerShell

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

Get-PartnerAzureBillingAccount - returns get_SerializationSettings error #204

Closed cblackuk closed 4 years ago

cblackuk commented 4 years ago

Steps to reproduce

PS C:\AzureStackDeployment\modules> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     5.8.3      AzureRM.profile                     {Add-AzureRmEnvironment, Clear-AzureRmContext, Clear-AzureRmDefault, Connect-AzureRmAccount...}
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
Script     2.0.1911.5 PartnerCenter                       {Add-PartnerCustomerCartLineItem, Add-PartnerCustomerUserRoleMember, Connect-PartnerCenter, Disconnect-PartnerCenter...}
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

PS C:\AzureStackDeployment\modules> Get-PartnerAzureBillingAccount -Verbose -Debug
Get-PartnerAzureBillingAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Billing.BillingManagementClient' from assembly 'Microsoft.Azure.Management.Billing, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' does not have an implementation.
At line:1 char:1
+ Get-PartnerAzureBillingAccount -Verbose -Debug
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-PartnerAzureBillingAccount], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Store.PartnerCenter.PowerShell.Commands.GetPartnerAzureBillingAccount

Started with https://github.com/microsoft/Partner-Center-PowerShell/issues/200

cblackuk commented 4 years ago

@isaiahwilliams looks like AzureRM.Profile might be causing it as I can reproduce the other error now from https://github.com/microsoft/Partner-Center-PowerShell/issues/200:

PS C:\> Update-Module -Name PartnerCenter -Verbose -Force
VERBOSE: Checking for updates for module 'PartnerCenter'.
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'True'; IsRegistered = 'True'.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: Using the specified source names : 'PSGallery'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PartnerCenter'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'PartnerCenter'.
VERBOSE: Performing the operation "Update-Module" on target "Version '2.0.1909.5' of module 'PartnerCenter', updating to version '2.0.1911.5'".
VERBOSE: The installation scope is specified to be 'AllUsers'.
VERBOSE: The specified module will be installed in 'C:\Program Files\WindowsPowerShell\Modules'.
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'PartnerCenter' with version '2.0.1911.5' from the repository 'https://www.powershellgallery.com/api/v2'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PartnerCenter'' for ''.
VERBOSE: InstallPackage' - name='PartnerCenter', version='2.0.1911.5',destination='C:\Users\ContainerAdministrator\AppData\Local\Temp\461795022'
VERBOSE: DownloadPackage' - name='PartnerCenter', version='2.0.1911.5',destination='C:\Users\ContainerAdministrator\AppData\Local\Temp\461795022\PartnerCenter\PartnerCenter.nupkg',
uri='https://www.powershellgallery.com/api/v2/package/PartnerCenter/2.0.1911.5'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/PartnerCenter/2.0.1911.5'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/PartnerCenter/2.0.1911.5'.
VERBOSE: Completed downloading 'PartnerCenter'.
VERBOSE: Hash for package 'PartnerCenter' does not match hash provided from the server.
VERBOSE: InstallPackageLocal' - name='PartnerCenter', version='2.0.1911.5',destination='C:\Users\ContainerAdministrator\AppData\Local\Temp\461795022'
VERBOSE: Catalog file 'PartnerCenter.cat' is not found in the contents of the module 'PartnerCenter' being installed.
VERBOSE: Valid authenticode signature found in the file 'PartnerCenter.psd1' for the module 'PartnerCenter'.
VERBOSE: For publisher validation, current module 'PartnerCenter' with version '2.0.1911.5' with publisher name 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module
signed by Microsoft: 'True'.
VERBOSE: For publisher validation, using the previously-installed module 'PartnerCenter' with version '2.0.1909.5' under 'C:\Program Files\WindowsPowerShell\Modules\PartnerCenter\2.0.1909.5' with publisher name 'CN=Microsoft Root
Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module signed by Microsoft: 'True'.
VERBOSE: Authenticode issuer 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of the new module 'PartnerCenter' with version '2.0.1911.5' matches with the authenticode issuer
'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of the previously-installed module 'PartnerCenter' with version '2.0.1909.5'.
VERBOSE: Module 'PartnerCenter' was installed successfully to path 'C:\Program Files\WindowsPowerShell\Modules\PartnerCenter\2.0.1911.5'.
PS C:\> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

PS C:\> Connect-PartnerCenter -AccessToken $CSPToken

Account                                  Environment                                                                                       TenantId
-------                                  -----------                                                                                       --------
                                         AzureCloud                                                                                        common

PS C:\> Get-PartnerAzureBillingAccount -Verbose -Debug
Get-PartnerAzureBillingAccount : Operation returned an invalid status code 'Unauthorized'
At line:1 char:1
+ Get-PartnerAzureBillingAccount -Verbose -Debug
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-PartnerAzureBillingAccount], ErrorResponseException
    + FullyQualifiedErrorId : Microsoft.Azure.Management.Billing.Models.ErrorResponseException,Microsoft.Store.PartnerCenter.PowerShell.Commands.GetPartnerAzureBillingAccount
cblackuk commented 4 years ago

Yep 100% confirmed - still needs fixing ;-P

PS C:\> Import-Module AzureRM.profile
PS C:\> Update-Module -Name PartnerCenter -Verbose -Force
VERBOSE: Checking for updates for module 'PartnerCenter'.
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'True'; IsRegistered = 'True'.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: Using the specified source names : 'PSGallery'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PartnerCenter'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'PartnerCenter'.
VERBOSE: Performing the operation "Update-Module" on target "Version '2.0.1909.5' of module 'PartnerCenter', updating to version '2.0.1911.5'".
VERBOSE: The installation scope is specified to be 'AllUsers'.
VERBOSE: The specified module will be installed in 'C:\Program Files\WindowsPowerShell\Modules'.
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'PartnerCenter' with version '2.0.1911.5' from the repository 'https://www.powershellgallery.com/api/v2'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PartnerCenter'' for ''.
VERBOSE: InstallPackage' - name='PartnerCenter', version='2.0.1911.5',destination='C:\Users\ContainerAdministrator\AppData\Local\Temp\2036241396'
VERBOSE: DownloadPackage' - name='PartnerCenter', version='2.0.1911.5',destination='C:\Users\ContainerAdministrator\AppData\Local\Temp\2036241396\PartnerCenter\PartnerCenter.nupkg',
uri='https://www.powershellgallery.com/api/v2/package/PartnerCenter/2.0.1911.5'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/PartnerCenter/2.0.1911.5'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/PartnerCenter/2.0.1911.5'.
VERBOSE: Completed downloading 'PartnerCenter'.
VERBOSE: Hash for package 'PartnerCenter' does not match hash provided from the server.
VERBOSE: InstallPackageLocal' - name='PartnerCenter', version='2.0.1911.5',destination='C:\Users\ContainerAdministrator\AppData\Local\Temp\2036241396'
VERBOSE: Catalog file 'PartnerCenter.cat' is not found in the contents of the module 'PartnerCenter' being installed.
VERBOSE: Valid authenticode signature found in the file 'PartnerCenter.psd1' for the module 'PartnerCenter'.
VERBOSE: For publisher validation, current module 'PartnerCenter' with version '2.0.1911.5' with publisher name 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module
signed by Microsoft: 'True'.
VERBOSE: For publisher validation, using the previously-installed module 'PartnerCenter' with version '2.0.1909.5' under 'C:\Program Files\WindowsPowerShell\Modules\PartnerCenter\2.0.1909.5' with publisher name 'CN=Microsoft Root
Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module signed by Microsoft: 'True'.
VERBOSE: Authenticode issuer 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of the new module 'PartnerCenter' with version '2.0.1911.5' matches with the authenticode issuer
'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of the previously-installed module 'PartnerCenter' with version '2.0.1909.5'.
VERBOSE: Module 'PartnerCenter' was installed successfully to path 'C:\Program Files\WindowsPowerShell\Modules\PartnerCenter\2.0.1911.5'.
PS C:\> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     5.8.3      AzureRM.profile                     {Add-AzureRmEnvironment, Clear-AzureRmContext, Clear-AzureRmDefault, Connect-AzureRmAccount...}
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

PS C:\> Connect-PartnerCenter -AccessToken $CSPToken

Account                                  Environment                                                                                       TenantId
-------                                  -----------                                                                                       --------
                                         AzureCloud                                                                                        common

PS C:\> Get-PartnerAzureBillingAccount -Verbose -Debug
Get-PartnerAzureBillingAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Billing.BillingManagementClient' from assembly 'Microsoft.Azure.Management.Billing, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' does not have an implementation.
At line:1 char:1
+ Get-PartnerAzureBillingAccount -Verbose -Debug
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-PartnerAzureBillingAccount], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Store.PartnerCenter.PowerShell.Commands.GetPartnerAzureBillingAccount
ghost commented 4 years ago

Thank you for sharing this information, the root cause for this issue has to deal with a compatibility issue. The same issue that impacts compatibility between the Az and AzureRm modules also impacts AzureRm and PartnerCenter. If you are using PowerShell 5.1, then I would recommend install PowerShell Core and leverage the Az module for Azure.

This way if you still have a dependency on the AzureRm module you can use PowerShell 5.1 for that and PowerShell Core for Partner Center.

cblackuk commented 4 years ago

I wish I could my friend but I work on Azure Stack Hub and I do not have the option to use Az modules. I have to make it all work with this: https://www.powershellgallery.com/packages/AzureStack/1.8.0

Which is:

$module = Get-Module AzureRM.Profile 
if ($module -ne $null -and $module.Version.ToString().CompareTo("5.8.3") -lt 0) 
{ 
    Write-Error "This module requires AzureRM.Profile version 5.8.3. An earlier version of AzureRM.Profile is imported in the current PowerShell session. Please open a new session before importing this module. This error could indicate that multiple incompatible versions of the Azure PowerShell cmdlets are installed on your system. Please see https://aka.ms/azps-version-error for troubleshooting information." -ErrorAction Stop 
} 
elseif ($module -eq $null) 
{ 
    Import-Module AzureRM.Profile -MinimumVersion 5.8.3 -Scope Global 
}
Import-Module AzureRM.Resources -RequiredVersion 6.4.3 -Global
Import-Module Azs.AzureBridge.Admin -RequiredVersion 0.2.2 -Global
Import-Module Azs.Backup.Admin -RequiredVersion 0.3.2 -Global
Import-Module Azs.Commerce.Admin -RequiredVersion 0.2.2 -Global
Import-Module Azs.Compute.Admin -RequiredVersion 0.2.3 -Global
Import-Module Azs.Deployment.Admin -RequiredVersion 0.1.0 -Global
Import-Module Azs.Fabric.Admin -RequiredVersion 0.5.0 -Global
Import-Module Azs.Gallery.Admin -RequiredVersion 0.2.2 -Global
Import-Module Azs.InfrastructureInsights.Admin -RequiredVersion 0.3.2 -Global
Import-Module Azs.KeyVault.Admin -RequiredVersion 0.2.2 -Global
Import-Module Azs.Network.Admin -RequiredVersion 0.2.2 -Global
Import-Module Azs.Storage.Admin -RequiredVersion 0.2.3 -Global
Import-Module Azs.Subscriptions -RequiredVersion 0.2.2 -Global
Import-Module Azs.Subscriptions.Admin -RequiredVersion 0.3.3 -Global
Import-Module Azs.Update.Admin -RequiredVersion 0.2.3 -Global
cblackuk commented 4 years ago

So the question is... why other cmdlets work fine but not this one? :)

ghost commented 4 years ago

This command is impacted by this particular issue because the library being used was generated using the same process used to build the Azure SDK and the new parts of the Az module. So, it has different dependencies then the Partner Center operations. Fortunately you can have PowerShell 5.1 and PowerShell Core installed side by side. Which means you can leverage PowerShell Core for executing these commands and it will not have any impact on your existing scripts.

cblackuk commented 4 years ago

Not in the Automation Runbook you cannot ;-(

cblackuk commented 4 years ago

On new module at least debug does something:

PS C:\AzureStackDeployment\modules> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
Script     2.0.1911.6 PartnerCenter                       {Add-PartnerCustomerCartLineItem, Add-PartnerCustomerUserRoleMember, Connect-PartnerCenter, Disconnect-PartnerCenter...}
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}

PS C:\AzureStackDeployment\modules> Get-PartnerAzureBillingAccount -Verbose -Debug

Confirm
Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Billing.BillingManagementClient' from assembly 'Microsoft.Azure.Management.Billing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an
implementation.
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a
Get-PartnerAzureBillingAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Billing.BillingManagementClient' from assembly 'Microsoft.Azure.Management.Billing, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' does not have an implementation.
At line:1 char:1
+ Get-PartnerAzureBillingAccount -Verbose -Debug
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-PartnerAzureBillingAccount], TypeLoadException
    + FullyQualifiedErrorId : Microsoft.Store.PartnerCenter.PowerShell.Commands.GetPartnerAzureBillingAccount
cblackuk commented 4 years ago

@isaiahwilliams so any idea what can I do in this case as this error will never allow me to automate anything ever again... if the new module requires .NET Core/Az module and is not compatible with PS 5.1 - what can I do here? If I load them in different order then the normal ARM cmdlets break like:

PS C:\AzureStackDeployment\modules> Disconnect-AzureRmAccount
Disconnect-AzureRmAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.Commands.ResourceManager.Common, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
At line:1 char:1
+ Disconnect-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Disconnect-AzureRmAccount], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.DisconnectAzureRmAccountCommand
ghost commented 4 years ago

@cblackuk help me understand what you trying to accomplish here. The Get-PartnerAzureBilling* commands are currently only used to get information used to create additional Azure subscriptions under an Azure Plan. With this in mind you should be able to load the Azure modules first and it will enable you to work around impacting the AzureRm cmdlets. However, it will mean that a separate process will be needed if you need to create an additional subscriptions for an Azure Plan.

cblackuk commented 4 years ago

@isaiahwilliams I am just trying to make it all future-proof if you will and be able to continue on-board/off-board customers with the addition of Azure Plans without needed a separate process for Azure Plan specific tasks. Currently I can do all of it, end-to-end in one runbook or container - but with the inability to use AzureRM modules or AzureBilling modules simultaneously - it is a massive issue for me. Hopefully, that makes some sense?

ghost commented 4 years ago

This definitely make sense, and unfortunately there is not a simple solution here due to the dependencies being used. Currently there will be a compatibility issue with the AzureRM module and if it is corrected that will lead to a compatibility issue with the Az module. So, I think that the best option here would be to leverage the Invoke-RestMethod for the command that will result in this error. As the plans for future updates take shape I will see if we can devise a solution for this blocker.