Issue
$myObj = @{
PSDependOptions = @{
Target = 'CurrentUser'
}
AwesomeModule = @{
Version= 'latest'
Tags = 'deploy'
}
AnotherAwesomeModule = @{
Version= 'latest'
Tags = 'test'
}
}
Invoke-PSDepend -InputObject $myObj -Install -Import -Tags Deploy
After this command, PSDependOptions item is removed from myObj:
$myObj.Keys | % {$_}
AwesomeModule
AnotherAwesomeModule
So, if i recall Invoke-PSDepend:
Invoke-PSDepend -InputObject $myObj -Install -Import -Tags Test
the module will be installed in AllUser , not in the CurrentUser (the setted target).
Causes
I found the Invoke-PSDepend.ps1 script pass InputObject by reference to internal GetPSDependParams variable [code].
So, when Parse-Dependency function in Get-Dependency.ps1 script remove the PSDependOptions item [code] also it is removed from original object.
Solution
Clone the object instead of pass by reference in this row:
$GetPSDependParams.add('InputObject',$InputObject)
to
$GetPSDependParams.add('InputObject', $($InputObject.Clone()))
Workaround
Clone the object before passing it to the parameter.
Issue
After this command,
PSDependOptionsitem is removed frommyObj:So, if i recall Invoke-PSDepend:
the module will be installed in
AllUser, not in theCurrentUser(the setted target).Causes
I found the
Invoke-PSDepend.ps1script passInputObjectby reference to internalGetPSDependParamsvariable [code].So, when
Parse-Dependencyfunction inGet-Dependency.ps1script remove thePSDependOptionsitem [code] also it is removed from original object.Solution
Clone the object instead of pass by reference in this row:
$GetPSDependParams.add('InputObject',$InputObject)to
$GetPSDependParams.add('InputObject', $($InputObject.Clone()))Workaround
Clone the object before passing it to the parameter.