Does PowerShell Core 6.1 not automatically import modules..

…when you use any commands in that module?

The reason why I am asking is because I have installed “AWSPowerShell.<wbr />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.

'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:

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

Thanks for replying :slight_smile:

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…

@Kiran

When I run “$PSModuleAutoLoadingPreference” no value is returned.

Okay, then set it to ‘All’

[pre]

$PSModuleAutoloadingPreference = ‘All’

[/pre]

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

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:

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.

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

 

 

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

[pre]

PS C:&gt; Get-Module -ListAvailable

ModuleType Name ExportedCommands


Manifest AppLocker {}
Manifest BitsTransfer {}
Manifest PSDiagnostics {}
Manifest TroubleshootingPack {}
Manifest AWSPowerShell {Update-EBApplicationVersion, Set-DPStatus, Remove-IAMGroupPol…

[/pre]

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>

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>

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.

Wow - great work Guys :slight_smile:

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

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.

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.