Skip to content

Object passed to InputObject parameter is modified by module #35

@ghost

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions