Does PowerShell Core 6.1 not automatically import modules..

Welcome Forums General PowerShell Q&A Does PowerShell Core 6.1 not automatically import modules..

This topic contains 14 replies, has 4 voices, and was last updated by

 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #132750

    Participant
    Topics: 7
    Replies: 14
    Points: 25
    Rank: Member

    ..when you use any commands in that module?

    The reason why I am asking is because I have installed "AWSPowerShell.NetCore" but I can't run any commands

    (eg Get-AGRestApiList) in a session until i run "import-Module awspowershell.netcore".

    I tested this in Powershell 5.1 and everything works as expected.

  • #132764

    Participant
    Topics: 3
    Replies: 40
    Points: 79
    Helping Hand
    Rank: Member

    'No, and the $PSModulePath is also different.

    There is a preference variable you can configure to auto load modules just like you can in Windows PowerShell.

    Also, your profile path is different in PowerShell 6.

    If you'll recall in Windows PowerShell, you may have had to create a folder in your user Documents folder and configure a custome profile script. The same needs to be done for PowerShell 6.

    Just create the same folder structure as before but call this folder 'PowerShell' instead of 'WindowsPowerShell'.

     

    Here's some additional help:

    PowerShell v6: #4 profiles

  • #132765

    Participant
    Topics: 0
    Replies: 78
    Points: 416
    Helping Hand
    Rank: Contributor

    Hi Ciaran – Default nature is implicit load unless $PSModuleAutoLoadingPreference is set to 'none'. Please check the value of $PSModuleAutoLoadingPreference preferance variable.

  • #132768

    Participant
    Topics: 7
    Replies: 14
    Points: 25
    Rank: Member

    Thanks for replying 🙂

    Yep, I put the command "import-Module awspowershell.netcore" into my $profile for 6.1.

    I guess they are going to fix the autoloading of modules in PowerShell Core at some time..

  • #132770

    Participant
    Topics: 7
    Replies: 14
    Points: 25
    Rank: Member

    @kiran

    When I run "$PSModuleAutoLoadingPreference" no value is returned.

  • #132774

    Participant
    Topics: 0
    Replies: 78
    Points: 416
    Helping Hand
    Rank: Contributor

    Okay, then set it to 'All'

    
    $PSModuleAutoloadingPreference = 'All'
    
    

    By the way, did you install the module in PowerShell Core or in Windows PowerShell?

  • #132780

    Participant
    Topics: 3
    Replies: 40
    Points: 79
    Helping Hand
    Rank: Member

    Here is some light reading on how to work with the module path, which should then correct the issue of them not loading after you have set the preference:

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-6#environment-variables-that-store-preferences

    Also as already stated by Kiran, it's important to note if the module was installed originally. It's not a deal breaker as there is a compatibility module that you can install in PowerShell 6 that will allow you to import WindowsPowerShell modules.

    Hope this helps.

  • #132783

    Participant
    Topics: 7
    Replies: 14
    Points: 25
    Rank: Member

    Hi Kiran

    I've installed the module in both 5.1 and 6.1 core.

    1/ I've commented out the import on my $profile: #import-Module awspowershell.netcore

    2/ Then I ran $PSModuleAutoloadingPreference = 'All'

    3/ Started new session and running "Get-AGRestApiList" still doesn't work.

    As a further Test, I installed the module on an Ubuntu box and AWS Powershell commands won't work on it either until I run "Import-Module....".

    So, in conclusion, in a Windows box and a Ubuntu box, no AWS Powershell commands work until i run "import-Module awspowershell.netcore" first.

    As a workaround I have added "import-Module awspowershell.netcore" to my $profile on both boxes, so we are all good.

    thanks

     

     

  • #132788

    Participant
    Topics: 0
    Replies: 78
    Points: 416
    Helping Hand
    Rank: Contributor

    This is strange! Is the installed module listing in the Get-Command -ListAvailable??

    
    PS C:\> Get-Module -ListAvailable
    
    ModuleType Name ExportedCommands
    ———- —- —————-
    Manifest AppLocker {}
    Manifest BitsTransfer {}
    Manifest PSDiagnostics {}
    Manifest TroubleshootingPack {}
    Manifest AWSPowerShell {Update-EBApplicationVersion, Set-DPStatus, Remove-IAMGroupPol...
    
    
  • #132791

    Participant
    Topics: 7
    Replies: 14
    Points: 25
    Rank: Member

    Directory: C:\Program Files\PowerShell\Modules

    ModuleType Version Name PSEdition ExportedCommands
    ———- ——- —- ——— —————-
    Binary 3.3.428.0 AWSPowerShell.NetCore Core {Add-ASInstances, Add-CTTag, Add-D...

    Directory: C:\program files\powershell\6\Modules

    ModuleType Version Name PSEdition ExportedCommands
    ———- ——- —- ——— —————-
    Manifest 6.1.0.0 CimCmdlets Core {Get-CimAssociatedInstance, Get-Ci...
    Manifest 1.1.0.0 Microsoft.PowerShell.Archive Desk {Compress-Archive, Expand-Archive}
    Manifest 6.1.0.0 Microsoft.PowerShell.Diagnostics Core {Get-WinEvent, New-WinEvent}
    Manifest 6.1.0.0 Microsoft.PowerShell.Host Core {Start-Transcript, Stop-Transcript}
    Manifest 6.1.0.0 Microsoft.PowerShell.Management Core {Add-Content, Clear-Content, Clear...
    Manifest 6.1.0.0 Microsoft.PowerShell.Security Core {Get-Acl, Set-Acl, Get-PfxCertific...
    Manifest 6.1.0.0 Microsoft.PowerShell.Utility Core {Format-List, Format-Custom, Forma...
    Manifest 6.1.0.0 Microsoft.WSMan.Management Core {Disable-WSManCredSSP, Enable-WSMa...
    Script 1.1.7.2 PackageManagement Desk {Find-Package, Get-Package, Get-Pa...
    Script 1.6.7 PowerShellGet Desk {Find-Command, Find-DSCResource, F...
    Script 0.0 PSDesiredStateConfiguration Desk {Generate-VersionInfo, Get-Compati...
    Script 6.1.0.0 PSDiagnostics Core {Disable-PSTrace, Disable-PSWSManC...
    Script 2.0.0 PSReadLine Desk {Get-PSReadLineKeyHandler, Set-PSR...
    Binary 1.1.2 ThreadJob Desk Start-ThreadJob

    PS C:\Users\ciaran.kelly>

  • #132792

    Participant
    Topics: 7
    Replies: 14
    Points: 25
    Rank: Member

    And here's the output from my Ubuntu box:

    PS /home/ciaran> get-module -ListAvailable

    Directory: /usr/local/share/powershell/Modules

    ModuleType Version Name PSEdition ExportedCommands
    ———- ——- —- ——— —————-
    Binary 3.3.428.0 AWSPowerShell.NetCore Core {Add-ASInstances, Add-CTTag, Add-DPTags, Add-DSIpRoutes...}

    Directory: /snap/powershell/14/opt/powershell/Modules

    ModuleType Version Name PSEdition ExportedCommands
    ———- ——- —- ——— —————-
    Manifest 1.2.2.0 Microsoft.PowerShell.Archive Desk {Compress-Archive, Expand-Archive}
    Manifest 6.1.0.0 Microsoft.PowerShell.Host Core {Start-Transcript, Stop-Transcript}
    Manifest 6.1.0.0 Microsoft.PowerShell.Management Core {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}
    Manifest 6.1.0.0 Microsoft.PowerShell.Security Core {Get-Credential, Get-ExecutionPolicy, Set-ExecutionPolicy, ConvertFrom-...
    Manifest 6.1.0.0 Microsoft.PowerShell.Utility Core {Format-List, Format-Custom, Format-Table, Format-Wide...}
    Script 1.1.7.2 PackageManagement Desk {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
    Script 1.6.7 PowerShellGet Desk {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...}
    Script 0.0 PSDesiredStateConfiguration Desk {Write-NodeMOFFile, Initialize-ConfigurationRuntimeState, GetImplementi...
    Script 2.0.0 PSReadLine Desk {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remove-PSReadLineK...
    Binary 1.1.2 ThreadJob Desk Start-ThreadJob

    PS /home/ciaran>

  • #132809

    Participant
    Topics: 2
    Replies: 397
    Points: 689
    Helping Hand
    Rank: Major Contributor

    Found the issue.

    https://www.powershellgallery.com/packages/AWSPowerShell.NetCore/3.3.428.0/Content/AWSPowerShell.NetCore.psd1

    Looking at line 200-210 or so (the line numberings aren't quite matching up for me on Chrome) you can see they've defined FunctionsToExport and CmdletsToExport with wildcards, explicitly against best practices.

    Basically, this is guaranteed to break autoloading for binary modules, and frequently breaks autoloading for script modules as well. This is something the team that created the module will need to fix.

  • #132810

    Participant
    Topics: 7
    Replies: 14
    Points: 25
    Rank: Member

    Wow – great work Guys 🙂

    I guess someone should post a comment, letting them know of this bug? https://www.powershellgallery.com/packages/AWSPowerShell.NetCore/3.3.428.0

  • #132816

    Participant
    Topics: 0
    Replies: 78
    Points: 416
    Helping Hand
    Rank: Contributor

    I am not really sure whether this is a bug or not, because the module is exporting the aliases instead of functions, so this should work as expected.

  • #132825

    Participant
    Topics: 2
    Replies: 397
    Points: 689
    Helping Hand
    Rank: Major Contributor

    It's exporting the cmdlets and the aliases, but the aliases don't map to anything PS can recognise in the autoloader; for it to resolve the aliases, it'd have to fully import each module it's checking for the command you're trying to use, which would very much slow everything down and defeat the purpose of auto-loading.

    I don't know whether the team that created the module checks the gallery comments, but I'll leave a comment all the same. If there's another avenue of feedback we can pursue as well, that would be best.

The topic ‘Does PowerShell Core 6.1 not automatically import modules..’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort