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

adding support for switches: Force,AllowClobber,SkipPublisherCheck #337

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ function Get-TargetResource
Specifies a package provider name to which to scope your package search. You can get package provider names
by running the Get-PackageProvider cmdlet.

.PARAMETER Force
Forces the installation of modules. If a module of the same name and version already exists on the computer,
this parameter overwrites the existing module with one of the same name that was found by the command.

.PARAMETER AllowClobber
Allows the installation of modules regardless of if other existing module on the computer have cmdlets
of the same name

.PARAMETER SkipPublisherCheck
Allows the installation of modules that have not been catalog signed

.PARAMETER AdditionalParameters
Provider specific parameters that are passed as an Hashtable. For example, for NuGet provider you can
pass additional parameters like DestinationPath.
Expand Down Expand Up @@ -89,6 +100,18 @@ function Get-TargetResource
[Parameter()]
[System.String]
$ProviderName,

[Parameter()]
[Switch]
$Force,

[Parameter()]
[Switch]
$AllowClobber,
Copy link
Contributor

@jianyunt jianyunt Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First thank you very much for your PR. Here are my comments:

  1. any reasons you want to explicitly call out these parameters instead of using the existing $AdditionalParameters to pass them in?
  2. this DSC resource is a kind of generic for all OneGet providers. My concern is that not all the OneGet providers support force, AllowClobber, SkipPublisherCheck. If people choose to use other providers and this dsc resource, their scenario will be broken, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I did first try specifying these switches using $AdditionalParameters like this :
AdditionalParameters = @{
    Force = $true
}

However this threw errors when trying to convert the value to a switch. I believe this is because $PSBoundParameters is a key value store but switches don't take a value they are a bit special. This issue is also reported by others (#327)

  1. this is a good design in principle. But it also means that if other providers have switches we will not be able to use them. I've been trying to find a better way to pass switches (something like $AdditionalSwitches) in but without much success so far

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brywang-msft any ideas in the PM DSC module regarding AdditionalParameters ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just learnt that -AllowClobber doesn't exist for cmdlets in PackageManagement in WMF 5.0, looks like it is only present in 5.1 which means this approach I have wont work.

I'm happy if you want to close this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct AllowClobber does not exist in PackageManagement. It was added in PowerShellGet - a PackageManagement provider. Thanks @mrhockeymonkey.


[Parameter()]
[Switch]
$SkipPublisherCheck,

[Parameter()]
[Microsoft.Management.Infrastructure.CimInstance[]]$AdditionalParameters
Expand Down Expand Up @@ -198,6 +221,17 @@ function Test-TargetResource
Specifies a package provider name to which to scope your package search. You can get package provider names
by running the Get-PackageProvider cmdlet.

.PARAMETER Force
Forces the installation of modules. If a module of the same name and version already exists on the computer,
this parameter overwrites the existing module with one of the same name that was found by the command.

.PARAMETER AllowClobber
Allows the installation of modules regardless of if other existing module on the computer have cmdlets
of the same name

.PARAMETER SkipPublisherCheck
Allows the installation of modules that have not been catalog signed

.PARAMETER AdditionalParameters
Provider specific parameters that are passed as an Hashtable. For example, for NuGet provider you can
pass additional parameters like DestinationPath.
Expand Down Expand Up @@ -237,6 +271,18 @@ function Test-TargetResource
[Parameter()]
[System.String]
$ProviderName,

[Parameter()]
[Switch]
$Force,

[Parameter()]
[Switch]
$AllowClobber,

[Parameter()]
[Switch]
$SkipPublisherCheck,

[Parameter()]
[Microsoft.Management.Infrastructure.CimInstance[]]$AdditionalParameters
Expand Down Expand Up @@ -298,6 +344,17 @@ function Set-TargetResource
Specifies a package provider name to which to scope your package search. You can get package provider names
by running the Get-PackageProvider cmdlet.

.PARAMETER Force
Forces the installation of modules. If a module of the same name and version already exists on the computer,
this parameter overwrites the existing module with one of the same name that was found by the command.

.PARAMETER AllowClobber
Allows the installation of modules regardless of if other existing module on the computer have cmdlets
of the same name

.PARAMETER SkipPublisherCheck
Allows the installation of modules that have not been catalog signed

.PARAMETER AdditionalParameters
Provider specific parameters that are passed as an Hashtable. For example, for NuGet provider you can
pass additional parameters like DestinationPath.
Expand Down Expand Up @@ -336,6 +393,18 @@ function Set-TargetResource
[Parameter()]
[System.String]
$ProviderName,

[Parameter()]
[Switch]
$Force,

[Parameter()]
[Switch]
$AllowClobber,

[Parameter()]
[Switch]
$SkipPublisherCheck,

[Parameter()]
[Microsoft.Management.Infrastructure.CimInstance[]]$AdditionalParameters
Expand Down
Binary file not shown.