microsoft / Partner-Center-PowerShell

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

Az.Accounts newer then 1.9.5 incompatible with partnercenter module #352

Open Agazoth opened 3 years ago

Agazoth commented 3 years ago

Steps to reproduce

Please see this error report: https://github.com/Azure/azure-powershell/issues/14288

With Az.Accounts 2.1.0 or higher installed run:

Connect-AzAccount

After login run

Import-Module partnercenter

Expected behavior

Module gets imported silently

Actual behavior

Import-Module partnercenter
Import-Module: Assembly with same name is already loaded

Diagnostic logs

 Import-Module partnercenter -Debug
VERBOSE: Loading module from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\partnercenter.psd1'.

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): a
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.PowerShell.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.PowerShell.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.Azure.Billing.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.Azure.Billing.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.Azure.Subscription.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.Azure.Subscription.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Graph.Beta.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Graph.Beta.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Graph.Core.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Graph.Core.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.Caching.Abstractions.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.Caching.Abstractions.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.Caching.Memory.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.Caching.Memory.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.DependencyInjection.Abstractions.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.DependencyInjection.Abstractions.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.Options.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.Options.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.Primitives.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Extensions.Primitives.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Identity.Client.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Identity.Client.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Identity.Client.Extensions.Msal.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Identity.Client.Extensions.Msal.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.IdentityModel.JsonWebTokens.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.IdentityModel.JsonWebTokens.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.IdentityModel.Logging.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.IdentityModel.Logging.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.IdentityModel.Tokens.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.IdentityModel.Tokens.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Rest.ClientRuntime.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Rest.ClientRuntime.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\System.Runtime.CompilerServices.Unsafe.dll'.
VERBOSE: Loading 'Executable' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\System.Runtime.CompilerServices.Unsafe.dll'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\Ax\Documents\PowerShell\Modules\partnercenter\3.0.10\Microsoft.Store.PartnerCenter.PowerShell.format.ps1xml'.
Import-Module: Assembly with same name is already loaded

Environment

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Agazoth commented 3 years ago

I guess this is the reason: Version 2.1.0 [Breaking Change] Removed Get-AzProfile and Select-AzProfile Replaced Azure Directory Authentication Library with Microsoft Authentication Library(MSAL)

penicaudm commented 3 years ago

Update Az module, then try to load PartnerCenter before Az.accounts I'm running latest Az PS at all times and haven't had the issue since.

I had the same issue which got fixed, and I've been running this at the start of my profile.ps1:

#
Write-Output "Begin profile.ps1"
Write-Output "Importing PartnerCenter" 
Import-module PartnerCenter 4>$null

Write-Output "Importing az.accounts"
Import-module Az.Accounts -ErrorAction Stop
cblackuk commented 3 years ago
PowerShell 7.1.2
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\Users\cblack> Import-module PartnerCenter 4>$null
PS C:\Users\cblack>
PS C:\Users\cblack> Write-Output "Importing az.accounts"
Importing az.accounts
PS C:\Users\cblack> Import-module Az.Accounts -ErrorAction Stop
PS C:\Users\cblack> Get-Module

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.2.5                 Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefa…
Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-It…
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Ob…
Script     3.0.6                 PartnerCenter                       {Add-PartnerCustomerCartLineItem, Add-PartnerCust…
Script     2.1.0                 PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, …

PS C:\Users\cblack> Connect-AzAccount
WARNING: INITIALIZATION: Fallback context save mode to process because of error during checking token cache persistence: Could not load file or assembly 'Microsoft.Identity.Client.Extensions.Msal, Version=2.16.2.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. The system cannot find the file specified..
WARNING: Unable to acquire token for tenant 'organizations'
Connect-AzAccount: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.21.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. The system cannot find the file specified.
nathan-given-health-catalyst commented 2 years ago

Hello, I'm running into this same issue. PS 7.2 PartnerCenter 3.0.10 Az.Accounts 2.6.2

Is the only workaround to downgrade az.accounts?

Update: I installed az.accounts 1.9.5 side-by-side with az.accounts 2.6.2 and I installed az.compute 4.5.0 side-by-side with az.compute 4.17.0 and by importing those explicit, older az modules I was able to get my stuff working.

ram-timhoogland commented 2 years ago

I'm running into this issue as well. I can install Az.Accounts 1.9.5 to get around the issue, but my script also requires Az.KeyVault to run, which automatically installs a more recent version of Az.Accounts.

nathan-given-health-catalyst commented 2 years ago

I'm running into this issue as well. I can install Az.Accounts 1.9.5 to get around the issue, but my script also requires Az.KeyVault to run, which automatically installs a more recent version of Az.Accounts.

I had to start using explicit import-module statements with -RequiredVersion parameter to get it to work. YMMV