您需要使用splatting operator。查看powershell 团队博客或此处的stackoverflow.com。
这是一个例子:
@'
param(
[string]$Name,
[string]$Street,
[string]$FavouriteColor
)
write-host name $name
write-host Street $Street
write-host FavouriteColor $FavouriteColor
'@ | Set-Content splatting.ps1
# you may pass an array (parameters are bound by position)
$x = 'my name','Corner'
.\splatting.ps1 @x
# or hashtable, basically the same as .\splatting -favouritecolor blue -name 'my name'
$x = @{FavouriteColor='blue'
Name='my name'
}
.\splatting.ps1 @x
在您的情况下,您需要这样称呼它:
$para = @{Name='name'; GUI=$true; desc='this is the description'; dryrun=$true}
. .\script1.ps1 @para