calling Invoke-Expression with Parameters in Powershell

前端 未结 2 1528
离开以前
离开以前 2021-01-12 07:42

I\'ve written a powershell module in c# that has a bunch of cmdlets like

Add-VM

The cmdlets reach out to an API and pull data back.

but for the sake

2条回答
  •  孤城傲影
    2021-01-12 08:17

    I know this is a little old now, but I was having a similar issue and a co-worker showed me that escaping $argstr prevents the object from getting converted to a string.

    Invoke-Expression "Add-VM `$argstr"
    

提交回复
热议问题