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

Commit a92d23d

Browse files
TravisEz13alerickson
authored andcommitted
Various fixes found while writing Invoke-DscResource (#518)
1 parent e62f6b9 commit a92d23d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

DSC/DSCResources/MSFT_PSModule/MSFT_PSModule.psm1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ function Get-TargetResource {
146146
# Check if the repository matches.
147147
$repositoryName = Get-ModuleRepositoryName -Module $latestModule -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
148148

149-
$installationPolicy = Get-InstallationPolicy -RepositoryName $repositoryName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
149+
if ($repositoryName) {
150+
$installationPolicy = Get-InstallationPolicy -RepositoryName $repositoryName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
151+
}
152+
150153
if ($installationPolicy) {
151154
$installationPolicyReturnValue = 'Trusted'
152155
}
@@ -389,7 +392,7 @@ function Set-TargetResource {
389392
$extractedArguments = New-SplatParameterHashTable -FunctionBoundParameters $PSBoundParameters `
390393
-ArgumentNames ('MinimumVersion', 'MaximumVersion', 'RequiredVersion')
391394

392-
Test-VersionParameter @extractedArguments
395+
$null = Test-VersionParameter @extractedArguments
393396

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

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

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

0 commit comments

Comments
 (0)