PoshCode / Configuration

A module to help other modules have settings
MIT License
176 stars 27 forks source link

Can't use Configuration in a module ScriptsToProcess script #11

Closed ghost closed 6 years ago

ghost commented 7 years ago
PS C:\git\junkcode\Powershell\Bravia\AlphaBravia> Import-Module .\AlphaBravia.psd1
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\Users\Adam\Documents\WindowsPowerShell\Modules\Configuration\1.0.2\Configuration.psm1:322 char:22
+         if(Test-Path $DefaultPath -Type Container) {
+                      ~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Test
   PathCommand

Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\Users\Adam\Documents\WindowsPowerShell\Modules\Configuration\1.0.2\Configuration.psm1:327 char:39
+         $Configuration = if(Test-Path $DefaultPath) {
+                                       ~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Test
   PathCommand

Update-Object : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\Users\Adam\Documents\WindowsPowerShell\Modules\Configuration\1.0.2\Configuration.psm1:362 char:26
+         $Configuration | Update-Object $Machine |
+                          ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Update-Object], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Update-Object

The code I'm calling in ScriptsToProcess is:

. ".\AlphaBravia.ps1"

Import-Configuration -Author "Adam Baxter" -Name "AlphaBravia"

I understand this might be backwards - what I'm trying to do is check if the module has already been configured, and prompt for a server name if not.

Jaykul commented 6 years ago

This is a known issue. I don't believe there's any way for me to fix it. If you're not calling it from a module member function, you would need to do something like this:

Get-Module AlphaBravia |  Import-Configuration

Or Pass the -CompanyName and -Name parameters