Skip to content

Creating aliases in ScriptsToProcess causes ipmo -force to fail #4520

@jianyunt

Description

@jianyunt

Cmdlet(s)

Any cmdlets under AzureRM.Websites.Netcore module

PowerShell Version

PS C:\test\Azure> $PSVersionTable

Name Value


PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.5
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Module Version

Manifest 0.9.1 AzureRM.Netcore

Description

Apparently, Websites has a ScriptsToProcess in psd1 file that looks like this:

@{
    "Swap-AzureRmWebAppSlot" = "Switch-AzureRmWebAppSlot";
}.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"

Unfortunately, `using module` is functionally the same as `Import-Module -Force` in that it runs ScriptsToProcess every time. So when her code runs, if the module has already imported, she gets this:

C:\users\jaiello\Documents\PowerShell\Modules\AzureRM.Websites.Netcore\0.9.1\netcoreapp2.0> Import-Module -force AzureRM
.Websites.Netcore
New-Alias : The alias is not allowed, because an alias with the name 'Swap-AzureRmWebAppSlot' already exists.
At C:\Users\jaiello\Documents\PowerShell\Modules\AzureRM.Websites.Netcore\0.9.1\netcoreapp2.0\WebsitesStartup.ps1:17
char:106
+ ... 'Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"
+                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceExists: (Swap-AzureRmWebAppSlot:String) [New-Alias], SessionStateException
    + FullyQualifiedErrorId : AliasAlreadyExists,Microsoft.PowerShell.Commands.NewAliasCommand

Script/Steps for Reproduction

PowerShellCore
Installed Azurerm.netcore

PS C:\> ipmo AzureRM.Websites.Netcore -force
New-Alias : The alias is not allowed, because an alias with the name 'Swap-AzureRmWebAppSlot' already exists.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions