Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Various fixes found while writing Invoke-DscResource #518

Merged
merged 1 commit into from
Aug 6, 2019
Merged
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
11 changes: 7 additions & 4 deletions DSC/DSCResources/MSFT_PSModule/MSFT_PSModule.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ function Get-TargetResource {
# Check if the repository matches.
$repositoryName = Get-ModuleRepositoryName -Module $latestModule -ErrorAction SilentlyContinue -WarningAction SilentlyContinue

$installationPolicy = Get-InstallationPolicy -RepositoryName $repositoryName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if ($repositoryName) {
$installationPolicy = Get-InstallationPolicy -RepositoryName $repositoryName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
}

if ($installationPolicy) {
$installationPolicyReturnValue = 'Trusted'
}
Expand Down Expand Up @@ -389,7 +392,7 @@ function Set-TargetResource {
$extractedArguments = New-SplatParameterHashTable -FunctionBoundParameters $PSBoundParameters `
-ArgumentNames ('MinimumVersion', 'MaximumVersion', 'RequiredVersion')

Test-VersionParameter @extractedArguments
$null = Test-VersionParameter @extractedArguments

try {
$extractedArguments = New-SplatParameterHashTable -FunctionBoundParameters $PSBoundParameters `
Expand Down Expand Up @@ -426,7 +429,7 @@ function Set-TargetResource {
# Extract the installation options.
$extractedSwitches = New-SplatParameterHashTable -FunctionBoundParameters $PSBoundParameters -ArgumentNames ('Force', 'AllowClobber', 'SkipPublisherCheck')

$moduleFound | Install-Module @extractedSwitches
$moduleFound | Install-Module @extractedSwitches 2>&1 | out-string | Write-Verbose
}
# The repository is untrusted but user's installation policy is trusted, so we install it with a warning.
elseif ($InstallationPolicy -ieq 'Trusted') {
Expand All @@ -436,7 +439,7 @@ function Set-TargetResource {
$extractedSwitches = New-SplatParameterHashTable -FunctionBoundParameters $PSBoundParameters -ArgumentNames ('AllowClobber', 'SkipPublisherCheck')

# If all the repositories are untrusted, we choose the first one.
$modules[0] | Install-Module @extractedSwitches -Force
$modules[0] | Install-Module @extractedSwitches -Force 2>&1 | out-string | Write-Verbose
}
# Both user and repository is untrusted
else {
Expand Down