powershell embedding one variable in another one

╄→尐↘猪︶ㄣ 提交于 2020-01-07 03:21:09

问题


In powershell , for a complicated reason an application needs a 6 character string as a sort of handle (Eg: abcdef) for a long asynchronous operation. I perform this using

$replaceHandle = "abcdef"
start-Job -handle $replaceHandle

The application stores the status of the asynchronous job in $abcdef (Prefixes string with $) and i can access parameters of job Status at any time by requesting

Get-Status -ID $abcdef.ID

Problem for me in my code is i am not able to get this $abcdef.ID properly I have tried $($jobVar.ToString()).ID - this gives blank/errors out maipulating $$jobVar.ID actually gives $'abcdef'.ID

How do i manage to get value of ($abcdef.ID) appropriately ?


回答1:


It because $jobVar is first interpreted :

try :

write-host "the value is $($jobVar.ID)"



回答2:


(Get-Variable $b -ValueOnly).Id

This worked



来源:https://stackoverflow.com/questions/16968837/powershell-embedding-one-variable-in-another-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!