Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 奇怪的变量名和替换其中的ID_Powershell - Fatal编程技术网

Powershell 奇怪的变量名和替换其中的ID

Powershell 奇怪的变量名和替换其中的ID,powershell,Powershell,请求帮助,因为我一整天都没有得到任何帮助 我有一个名为$text的变量,由Sciencelogic API填充,看起来像: echo $text /api/device/9767/aligned_app/6B2C342727896B9BED64AC156E55B7E0 : @{app_name=VMware: VirtualMachine Configuration; thresholds=} /api/device/9767/aligned_app/E28ED8DD41A89F3607DF8

请求帮助,因为我一整天都没有得到任何帮助

我有一个名为$text的变量,由Sciencelogic API填充,看起来像:

echo $text

/api/device/9767/aligned_app/6B2C342727896B9BED64AC156E55B7E0 : @{app_name=VMware: VirtualMachine Configuration; thresholds=}
/api/device/9767/aligned_app/E28ED8DD41A89F3607DF8A204FF0475E : @{app_name=VMware: VirtualMachine CPU Performance; thresholds=}
/api/device/9767/aligned_app/660405AB28B347B968862DDF0D788C00 : @{app_name=VMware: VirtualMachine Datastore Performance; thresholds=}
/api/device/9767/aligned_app/96AD6BCF5EE58CC5CECC2DC17CE818AD : @{app_name=VMware: VirtualMachine Disk Performance; thresholds=}
/api/device/9767/aligned_app/E0326A53EFDCDD3BF395904B0F640D1B : @{app_name=VMware: VirtualMachine Memory Performance; thresholds=}
/api/device/9767/aligned_app/37AB770954C374322E321C93F8061662 : @{app_name=VMware: VirtualMachine Network Performance; thresholds=}
/api/device/9767/aligned_app/9B20E399FDCE3C4AD06769A7DA54047B : @{app_name=VMware: VirtualMachine Storage Performance; thresholds=}
/api/device/9767/aligned_app/3626E5EB5D83AF6EBAEF53F157E5904B : @{app_name=VMware: VirtualMachine Uptime Performance; thresholds=}
名称中设备后面的第一个数字是设备ID($did),最后一个字符串是对齐的应用ID($appid)。 变量$did对于每个设备都是唯一的,并且有两个$appid值

要深入研究此数据,我需要调用一个相当笨拙的变量名,例如:

echo $text.'/api/device/9767/aligned_app/E0326A53EFDCDD3BF395904B0F640D1B'

app_name                                  thresholds                     
--------                                  ----------                     
VMware: VirtualMachine Memory Performance @{100=; 201-5=; 201-8=; 201-6=}
最终,我所追求的阈值是:

echo $text.'/api/device/9767/aligned_app/E0326A53EFDCDD3BF395904B0F640D1B'.thresholds.100

name                                 setting
----                                 -------
Physical Memory Utilization High     98.000 
现在我遇到的问题是$text在foreach循环中被调用,其中id发生变化。 所以我真正想说的是:

$did = 1234
$appid = "E0326A53EFDCDD3BF395904B0F640D1B"
$thresholds = $text.'/api/device/$did/aligned_app/$appid'.thresholds.100
但无论我如何尝试,都无法检索$text.'/api/device/$did/aligned_app/$appid'。阈值

我可以把它当作一个字符串,但如果你明白我的意思的话,我不能把它当作对数据的“调用”


我不知道如何更好地描述这个问题,形成一个句子,我可以在网上搜索,所以希望有人能帮助她

基本powershell:使用双引号以便解释变量。有关powershell中字符串文字的概述,请参阅链接文章和。基本powershell:使用双引号以便解释变量。有关powershell中字符串文字的概述,请参阅链接文章和。当您的答案有效时,请注意,您并没有解决OP的基本误解——期望单引号字符串中的变量被扩展——而简单地使用双引号字符串是更简单的解决方案:
$text./api/device/$did/aligned_app/$appid..thresholds.100
完全正确,但我(我的拙见;-))不喜欢“”中的变量,因为它看起来很混乱,如果你不小心,可能会造成麻烦…明白,但你的答案既不能告诉OP他们做错了什么,也不能解释这一点以及为什么你选择了不同的方法。非常感谢你们两位,因为你的答案有效,请注意,您并没有解决OP的基本误解——期望单引号字符串中的变量被扩展——而简单地使用双引号字符串是更简单的解决方案:
$text./api/device/$did/aligned_app/$appid..thresholds.100
完全正确,但我(我的拙见;-))不喜欢“”中的变量,因为它看起来很乱,如果你不小心,可能会引起麻烦…明白,但你的答案既不能告诉OP他们做错了什么,也不能解释这一点以及为什么你选择了不同的方法。非常感谢你们两位
$did = '9767'
$appid = 'E0326A53EFDCDD3BF395904B0F640D1B'
$text.('/api/device/' + $did + '/aligned_app/' + $appid).thresholds.100