Skip to content

Commit

Permalink
Merge pull request #10 from briantist/ModuleImportExistingBug
Browse files Browse the repository at this point in the history
Fix module import existing bug #9
  • Loading branch information
briantist authored Jul 8, 2017
2 parents 6297ee7 + 1fa0ef7 commit ae8303a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Binary file modified Idempotion.psd1
Binary file not shown.
11 changes: 8 additions & 3 deletions Public/Convert-DscResourceToCommand.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ param(
$ipmoParams[$paramName] = $PSBoundParameters[$paramName]
}

$newMod = New-Module @nmoParams -Verbose:$VerbosePreference
$newMod = New-Module @nmoParams -Verbose:$false

if ($AsCustomObject) { # Just return it directly if we opted for a custom object
$newMod
Expand All @@ -269,10 +269,15 @@ param(
If it shouldn't be imported, then we leave it removed and return it to the caller.
#>
$newMod | Remove-Module -Force -Verbose:$VerbosePreference
$newMod | Remove-Module -Force -Verbose:$false

if ($Import) { # PassThru will be in $ipmoParams so the module will be returned if needed
$newMod | Import-Module @ipmoParams -Global -Verbose:$VerbosePreference
if ($Force) {
Remove-Module -Name $newMod.Name -Force -ErrorAction Ignore -Verbose:$VerbosePreference
}
if ($Force -or -not (Get-Module -Name $newMod.Name -ErrorAction Ignore)) {
$newMod | Import-Module @ipmoParams -Global -Verbose:$VerbosePreference
}
} else {
$newMod # module is always returned if it's not imported
}
Expand Down

0 comments on commit ae8303a

Please sign in to comment.