Skip to content

#Requires -Modules causes error "Import-Module: Assembly with same name is already loaded" #13575

@JeremyTBradshaw

Description

@JeremyTBradshaw

Steps to reproduce

Call a script or function with #Requires -Modules [module info], while having the the required module installed. I've only tested with the PartnerCenter module, using either of these in my tests:

#Requires -Modules @{ModuleName='PartnerCenter';ModuleVersion='3.0.10'}, Az.Accounts

or

#Requires -Modules PartnerCenter

Both produce the same error when calling the script.

PS C:\Users\MY-USER> .\Documents\GitHub\PowerShell\Connect-PartnerCenterAsSecureApp.ps1
Import-Module: Assembly with same name is already loaded

The script I'm calling is very basic (https://github.com/JeremyTBradshaw/PowerShell/blob/master/Connect-PartnerCenterAsSecureApp.ps1)

Expected behavior

I expect the script to not fail immediately and instead carry on because I have the module that is required already installed, and it shouldn't matter if it is already loaded or not. For this example script, I should get prompted for the values of the mandatory properties whereas my example has omitted using any parameters.

PS C:\Users\MY-USER>.\Documents\GitHub\PowerShell\Connect-PartnerCenterAsSecureApp.ps1

cmdlet Connect-PartnerCenterAsSecureApp.ps1 at command pipeline position 1
Supply values for the following parameters:
CSPTenantId:

Actual behavior

PS C:\Users\MY-USER> .\Documents\GitHub\PowerShell\Connect-PartnerCenterAsSecureApp.ps1
Import-Module: Assembly with same name is already loaded

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions