Closed Jackbennett closed 2 years ago
@Jackbennett I would suggest that you follow the practices to have your module in a folder of C:\my-powershell\example\example.psm1
because if you want to package up the module further down the line to share with others it is better to have it all contained in a folder under the name of the module as this is what Publish-Module
will look for.
hope the above helps
TL:DR The workaround is to use the ManualOverride
parameterset and pass the -Company
(or -Author) and the module -Name
...
Basically, the problem you're having @Jackbennett is that the module stores configuration based on the author and module name, E.g.: AppData\PowerShell\CompanyOrAuthor\ModuleName
In order to determine the Company or Author automatically, it needs to have a manifest, and be installed somewhere I can find it (i.e. Get-Module YourModule -ListAvailable
needs to work) -- then it will read the metadata from there.
I can definitely look at putting an -ErrorAction SilentlyContinue
in that to prevent it from throwing, but the best case scenario would be that your data will end up in AppData\PowerShell\AnonymousModules\ModuleName
...
So, if you need to run from outside the PSModulePath, and especially if you want to avoid creating a manifest -- you have two options:
$PSScriptRoot\MyModuleConfiguration.psd1
so that you can read you configuration from the folder you're in without messing with the automatic config storage location guessing...If anyone's looking for an easy hacktoberfest contribution, going through the commands and making sure that there's an example of the ManualOverride
parameterset on all of them would be a good idea 😉
I was thinking just now that Get-Module -ListAvailable
works with a path to a PSD1 (rather than to the ModuleBase), so it's possible this could be fixed (now) with a code change for PS5.1+
Even though you can happily test a module as "c:\my-powershell\example.psm1" with
import-module -force c:\my-powershell\example.psm1
using import-configuration will create the error below. You'd have to rename the path "c:\example\example.psm1". I appreciate that's the name scheme you've got to have when putting the module into psmodulePath but for development it's a little restrictive.Inside my .psm1 with
$Script:Config = import-configuration
results in the following errorerror from line 99
I don't know if this is behaviour worth improving but I couldn't make a workaround if you might be able to suggest one. I have 72 projects in a folder it's quite nice organizing the powershell ones as prefixed with
ps-<modulename>
. Of course they don't get installed to psmodulepath with that pattern.