I'm building a menu and want to pass an array to a function as a reference.
When I'm passing just the reference everything works fine. But when I want to pass a second parameter, it won't work with an "ParameterBindingArgumentTransformationException". And I do not understand why.
Here is the - working- minimal code:
function Menu {
param([Ref]$mi)
Write-Host "var"
Write-Host $mi.value[0].cmd
Write-Host $mi.value[1].desc
Write-Output 0
}
function MainMenu {
$mm = @(@{desc='Windows Tools';cmd='WinToolsMenue'},
@{desc='copy setup.exe';cmd='setupexe'},
@{desc='gpupdate (Policy)';cmd='cmd /c gpupdate /force'},
@{desc='Exit';cmd='break'})
$a = Menu([Ref]$mm)
}
& MainMenu
The problem-code:
function Menu {
param([Ref]$mi, $b)
Write-Host $b
Write-Host $mi.value[0].cmd
Write-Host $mi.value[1].desc
Write-Output 0
}
function MainMenu {
$mm = @(@{desc='Windows Tools';cmd='WinToolsMenue'},
@{desc='copy setup.exe';cmd='setupexe'},
@{desc='gpupdate (Policy)';cmd='cmd /c gpupdate /force'},
@{desc='Exit';cmd='break'} )
$mm
$a = Menu([Ref]$mm, "b")
}
& MainMenu
Almost tried ([Ref]$mi), $b or ([Ref]$mi, $b), but it won't work. Someone out there who knows what I'm doing wrong?