powershell 将一个变量嵌入到另一个变量中 [英] powershell embedding one variable in another one

查看:51
本文介绍了powershell 将一个变量嵌入到另一个变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 powershell 中,出于复杂的原因,应用程序需要一个 6 个字符的字符串作为长异步操作的句柄(例如:abcdef).我使用

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

应用程序将异步作业的状态存储在 $abcdef 中(以 $ 为前缀的字符串)我可以随时通过请求访问作业状态的参数

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

我的代码中的问题是我无法正确获取此 $abcdef.ID我试过了$($jobVar.ToString()).ID - 这给出了空白/错误maipulating $$jobVar.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

我如何设法适当地获取 ($abcdef.ID) 的值?

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

推荐答案

这是因为 $jobVar 首先被解释:

It because $jobVar is first interpreted :

试试:

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

这篇关于powershell 将一个变量嵌入到另一个变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆