Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.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 如何从Get-AzureRmResourceGroup标记检索键值对_Powershell_Azure_Azure Resource Manager - Fatal编程技术网

Powershell 如何从Get-AzureRmResourceGroup标记检索键值对

Powershell 如何从Get-AzureRmResourceGroup标记检索键值对,powershell,azure,azure-resource-manager,Powershell,Azure,Azure Resource Manager,我有一个资源组,它使用一个具有键值对的标记进行调度:“IncludeInSchedule”:“true” 当我得到AzureRmResourceGroup-名称MyResourceGroup时,我看到: ResourceGroupName : MyResourceGroup Location : northcentralus ProvisioningState : Succeeded Tags : Name

我有一个资源组,它使用一个具有键值对的标记进行调度:“IncludeInSchedule”:“true”

当我得到AzureRmResourceGroup-名称MyResourceGroup时,我看到:

ResourceGroupName : MyResourceGroup
Location          : northcentralus
ProvisioningState : Succeeded 
Tags              :
                    Name               Value
                    =================  ======
                    IncludeInSchedule  True
ResourceId        : /subscriptions/ea904806-082f-4ce5-9b66-288afd61f83e/resourceGroups/MyResourceGroup
当我试图将标记中的值读入变量时,我就要崩溃了。它看起来像一个哈希表,但是
Get AzureRmResourceGroup-Name MyResourceGroup | Get Member Tags
表明它是一个哈希表数组,我读对了吗

Name MemberType Definition                 
---- ---------- ----------                 
Tags Property   hashtable[] Tags {get;set;}
如果我将Get-AzureRmResourceGroup的输出通过管道传输到Select对象中,并展开我获得的tags属性:

Name  Value
===== =====
Value True      
Name  IncludeInSchedule
这不是我期望看到的,我期望看到的是:

IncludeInSchedule  True
此外,当我尝试将标记分配给变量以便提取IncludeInSchedule值时,我没有看到任何值


如何从中提取值?

是的,
标记
是由
哈希表[]
定义的哈希表数组(注意方括号)

数组中的每个对象都是一个哈希表,如下所示:

$t = @{ Name = "IncludeInSchedule"; Value = "True" }

$t

Name                           Value
----                           -----
Value                          True
Name                           IncludeInSchedule 
要从您的对象访问此文件,请使用:

$IncludeInSchedule = ((Get-AzureRmResourceGroup -Name MyResourceGroup).Tags | Where-Object { $_.Name -eq 'IncludeInSchedule'}).Value

#Or

$IncludeInSchedule = (Get-AzureRmResourceGroup -Name MyResourceGroup).Tags | Where-Object { $_.Name -eq 'IncludeInSchedule'} | ForEach-Object { $_.Value }
输出:

PS C:\Users\frode> $IncludeInSchedule
True

是的,
Tags
是由
hashtable[]
定义的哈希表数组(注意方括号)

数组中的每个对象都是一个哈希表,如下所示:

$t = @{ Name = "IncludeInSchedule"; Value = "True" }

$t

Name                           Value
----                           -----
Value                          True
Name                           IncludeInSchedule 
要从您的对象访问此文件,请使用:

$IncludeInSchedule = ((Get-AzureRmResourceGroup -Name MyResourceGroup).Tags | Where-Object { $_.Name -eq 'IncludeInSchedule'}).Value

#Or

$IncludeInSchedule = (Get-AzureRmResourceGroup -Name MyResourceGroup).Tags | Where-Object { $_.Name -eq 'IncludeInSchedule'} | ForEach-Object { $_.Value }
输出:

PS C:\Users\frode> $IncludeInSchedule
True

根据微软的官方文档:

以下方面应起作用:

> (Get-AzureRmResourceGroup -Name MyResourceGroup).Tags.Value
True
您可以通过以下方式获取所有标签的密钥:

> (Get-AzureRmResourceGroup -Name MyResourceGroup).Tags.Keys
Value
Name
例如,我使用这种方式访问虚拟机的正常运行时间,如下所示:

> $vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName
> $vm.Tags.UptimeMonday
24h
如果您的命名与Microsoft的命名有任何冲突,它们会进一步说明:

如果键名与哈希表类型的某个属性名冲突,则可以使用PSBase访问这些属性。例如,如果密钥名为keys,并且希望返回密钥集合,请使用此语法


根据微软的官方文档:

以下方面应起作用:

> (Get-AzureRmResourceGroup -Name MyResourceGroup).Tags.Value
True
您可以通过以下方式获取所有标签的密钥:

> (Get-AzureRmResourceGroup -Name MyResourceGroup).Tags.Keys
Value
Name
例如,我使用这种方式访问虚拟机的正常运行时间,如下所示:

> $vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName
> $vm.Tags.UptimeMonday
24h
如果您的命名与Microsoft的命名有任何冲突,它们会进一步说明:

如果键名与哈希表类型的某个属性名冲突,则可以使用PSBase访问这些属性。例如,如果密钥名为keys,并且希望返回密钥集合,请使用此语法