Hello,
My task (or I should say Playing with Powershell Objects) is to create a custom object with the list of installed modules and update them. My oneliner creates the object and pipe it to Install-Module cmdlet, since it has -InputObject parameter which accepts pipeline ByValue,ByPropertyName I’m expecting below command should work - As per my understanding…
[-FullyQualifiedName] is looking for ModuleSpecification
It’s most likely that piping to Import-Module requires the FullyQualifiedName, not a short Name. You also notice that it want a ModuleSpecification. The preferred way would probably be to use Get-Module -ListAvailable to see if the module is available before piping to Import-Module:
Unless the parameter you’re passing to has been explicitly defined as [ValueFromPipelineByPropertyName()] in its code, it will not work like this. Also, if any previous parameter has a parameter that is [ValueFromPipeline()] it will attempt to put the entire object into that as well as doing what you’re expecting. This frequently breaks parameter sets and causes errors.
If you check Get-Help Install-Module -Full you’ll see that the first positional parameter is:
-Assembly
Required? true
Position? 0
Accept pipeline input? true (ByValue)
Parameter set name Assembly
Aliases None
Dynamic? false
Note - position 0
Note - pipeline input by value
It’s expecting you to provide an object that is some kind of Assembly, so it’s likely expecting direct input from an imported DLL or some such. I can’t say I’ve ever see the -Assembly parameter used.
Funky thing here is that -Name is ALSO position 0 – but there doesn’t appear to be a clear way for the PowerShell parser to determine which parameter set you want, so I’d conjecture it probably defaults to -Assembly.
Just throwing this out there… `install-module -Name ’ so `install-module -Name ‘SqlServer’,‘ImportExcel’ -Confirm:$false -Force` should work. Taking your array and passing could be done, don’t have time to write that up. I would recommend adding the -Confirm:$false -Force so you do not have to confirm all the modules to be install.
But some commands can be a little dinky about custom objects. I’d tend to use Trace-Command and get it to show me what it was doing for parameter binding, to figure out what was happening.