Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
从Get-AzResource | Where对象{}-Azure修剪ResourceId_Azure_Powershell - Fatal编程技术网

从Get-AzResource | Where对象{}-Azure修剪ResourceId

从Get-AzResource | Where对象{}-Azure修剪ResourceId,azure,powershell,Azure,Powershell,我正在尝试更新使用where对象过滤器生成的资源数组上的标记,该过滤器用于仅拾取未标记的资源。由于ResourceId为空,更新AzTag失败,但是如果我根据名称筛选资源,则命令可以正常工作。我注意到很多时候ResourceId只是被修剪过,缺少最后10个字符 $resources = Get-AzResource | Where-Object {$_.Tags -eq $null} $tags = @{"owner"="pmantz"; "pr

我正在尝试更新使用where对象过滤器生成的资源数组上的标记,该过滤器用于仅拾取未标记的资源。由于ResourceId为空,更新AzTag失败,但是如果我根据名称筛选资源,则命令可以正常工作。我注意到很多时候ResourceId只是被修剪过,缺少最后10个字符

$resources = Get-AzResource | Where-Object {$_.Tags -eq $null}
$tags = @{"owner"="pmantz"; "product"="product"}
foreach ($resource in $resources) {
     Update-AzTag -ResourceId $resource.Id -Tag $tags -Operation Merge
}
使用
$resources=Get-AzResource |其中对象{$\.Name-eq“Name”}
工作正常

你知道是什么引起的吗

问题似乎在于resourceid值,出于某种原因,即使像这样简单地使用它们,对于现有资源也是失败的

Update-AzTag -ResourceId "/subscriptions/.../resourceGroups/Azure-Splunk-Monitor-AppStg/providers/microsoft.insights/alertrules/xms2_origDTUAlertOver80Percent" -Tag $tags -Operation Merge
Update-AzTag: {"code":"TargetResourceNotFound","message":"The target resource id '/subscriptions/.../resourceGroups/xm-staging1-westus-uemy/providers/Microsoft.Sql/servers/xmsdb-xm-staging1-westus-uemy/datab
ases/xms2_orig' was not found."}
同时,让AzResource工作正常

Get-AzResource -ResourceId /subscriptions/.../resourceGroups/Azure-Splunk-Monitor-AppStg/providers/microsoft.insights/alertrules/xms2_origDTUAlertOver80Percent

Name              : xms2_origDTUAlertOver80Percent
ResourceGroupName : Azure-Splunk-Monitor-AppStg
ResourceType      : Microsoft.Insights/alertRules
Location          : westus
ResourceId        : /subscriptions/.../resourceGroups/Azure-Splunk-Monitor-AppStg/prov
                    iders/microsoft.insights/alertrules/xms2_origDTUAlertOver80Percent
Tags              :
                    Name
                                                                                                           Value
                    ===================================================================================================
                    =====================================================================================  ========
                    hidden-link:/subscriptions/.../resourceGroups/xm-staging1-westus-u
                    emy/providers/Microsoft.Sql/servers/xmsdb-xm-staging1-westus-uemy/databases/xms2_orig  Resource
更新


显然,所讨论的警报规则与已删除的资源关联,这些资源阻止了警报规则本身的标记。

因为它的
$resource.resourceId

不是它。id是ResourceId的别名实际上,我一直在用一个简单的azet资源来使用它。Where对象是破坏这一点的原因,但我不知道为什么你对别名的看法是正确的,但是Where对象没有破坏任何东西,它对我来说很好,这很奇怪,因为我已经在我的PC、Azure Vm和Azure automation上进行了测试,但它在任何地方都不起作用。提供的答案被标记为低质量帖子供审查。以下是一些指导原则。这一答案可以从解释中获益。仅代码答案不被视为“好”答案。这并不能回答这个问题。若要评论或要求作者澄清,请在其帖子下方留下评论。-
$resource |更新AzTag-Tag$tags-Operation Merge
有效吗?(根据
ResourceId
参数的位置为0并接受管道输入)