Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set AllowClobber on PackageManagement DSC via AdditionalParameters property #327

Open
djwork opened this issue Dec 14, 2017 · 8 comments

Comments

@djwork
Copy link

djwork commented Dec 14, 2017

Can't set AllowClobber on PackageManagement DSC via AdditionalParameters property

    PackageManagement CarbonModule
    {
        Name = 'Carbon'
        MinimumVersion = '2.5.0'
        ProviderName = 'PowerShellGet'
        Source = 'MyRepository'
        Ensure = 'Present'
        AdditionalParameters = @{'AllowClobber' = $true; 'Force' = $true}
        DependsOn = '[AEMORepository]repository'
    }

getting following error from the DSC operations event log
Cannot convert 'System.String' to the type 'System.Management.Automation.SwitchParameter'

exact the same as this report:
smurawski/dsc_contrib#1

@DCAG
Copy link

DCAG commented Jan 3, 2018

I get the same error with Additional Paraemter ExcludeVersion:
Cannot convert 'System.String' to the type 'System.Management.Automation.SwitchParameter' required by parameter 'ExcludeVersion'.

PackageManagement NugetPackage 
{ 
    Ensure               = "Present"  
    Name                 = "Package"
    AdditionalParameters = @{"Destination" = 'P:\Workspace\TestDrive\nuget\installed\'; "ExcludeVersion"=$true}
    RequiredVersion      = "11.27.20171114.1" 
    DependsOn            = "[PackageManagementSource]LocalSourceRepository"
}

@mrhockeymonkey
Copy link

I came across this issue today at work also. I added support for switches as a work around but it would be great to get this into the next release (#337)

If anyone has any suggestions or issue please let me know. I have done some testing but I couldn't see any documented process around updating DSCResources.

@vicp-iq
Copy link

vicp-iq commented Jan 16, 2019

I ran across this too. I propose that it could be resolved by replacing https://github.com/OneGet/oneget/blob/WIP/src/Microsoft.PackageManagement.DscResources/MSFT_PackageManagement/MSFT_PackageManagement.psm1#L106
and
https://github.com/OneGet/oneget/blob/WIP/src/Microsoft.PackageManagement.DscResources/MSFT_PackageManagement/MSFT_PackageManagement.psm1#L359

with

             $out = $null
             $value = $instance.Value
             if ([bool]::TryParse($instance.Value, [ref]$out)) {
                $value = $out 
             } 

             $null = $PSBoundParameters.Add($instance.Key, $value)

@mrhockeymonkey
Copy link

The fix for this actually got merged into the PowerShellGet module here: https://github.com/PowerShell/PowerShellGet/pull/347/files

I'm not sure that this has been released to PSGallery yet but when it does using this module should be used as it will have ongoing support

@ghost
Copy link

ghost commented Sep 21, 2020

not fixed yet? :( i'm plan to use PackageManagement DSC resource to CD our nupkg'd software but now its useless now without additional switches usage ability

@jrykowski-huron
Copy link

This is still an issue. Force, AllowClobber ... these need to be supported or at least Switch parameters like those handled as part of the generic AdditionalParameters property as proposed earlier:

AdditionalParameters = @{'AllowClobber' = $true; 'Force' = $true}

@jberezanski
Copy link

jberezanski commented Feb 23, 2021

It is also a problem when trying to ensure a PowerShell module is at least at a specific minimum version (but allowing a newer version to be present on the machine, without forcibly installing an older version, which is what using RequiredVersion would cause). When setting only MinimumVersion and an older version of that module exists, the PowerShellGet provider will not upgrade the module unless InstallUpgrade is passed (via AdditionalParameters). But InstallUpgrade is a switch, so it runs into the same bug ("Cannot convert...") as described here for other switches.

@jberezanski
Copy link

And using the PSModule resource from PowerShellGet comes with its own problem - that resource does not properly detect "metadata-only" modules (modules which only depend on other modules), such as Az, because it uses Get-Module -ListAvailable instead of Get-InstalledModule. So PackageManagement wins here - if only it supported passing switches...

jberezanski added a commit to jberezanski/oneget that referenced this issue Feb 24, 2021
… switch or bool

Syntax:
AdditionalParameters = @{ '[switch]InstallUpdate' = 'True' }

Fixes OneGet#327.
jberezanski added a commit to jberezanski/oneget that referenced this issue Feb 24, 2021
… switch or bool

Syntax:
AdditionalParameters = @{ '[switch]InstallUpdate' = 'True' }

Fixes OneGet#327.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants