Running this below and can't seem to get the collection correct to pass into the ForEach loop, even though it returns the names I want. $RGInfo returns as expected. But when I pass it into the loop to Set-AzureRmResourceGroup, it errors as below
PS H:\> $rginfo
ResourceGroupName
-----------------
rg-crp-d365-bp-n
rg-crp-d365-dev1-n
rg-crp-d365-dev2-n
rg-crp-d365-upgrad-n
$RGInfo = Get-AzureRmResourceGroup | Where-Object {$_.ResourceGroupName -like "RG-CRP-D365*" } | Select-Object ResourceGroupName
ForEach ($RGName in $RGInfo) {
If ($RGName.Tags -eq $null) {
Set-AzureRmResourceGroup -ResourceGroupName $RGName -Tag @{BUSINESS_UNIT="CRP"; COST_CENTER="6435" }
}
}
Know why I keep getting the below? There are four RG's so the ForEach loop is functional.
Set-AzureRmResourceGroup : 'resourceGroupName' does not match expected pattern '^[-\w._()]+$'. At line:7 char:2 + Set-AzureRmResourceGroup -ResourceGroupName $RGName -Tag @{BUSINESS_ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmResourceGroup], ValidationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetA
zureResourceGroupCmdlet Set-AzureRmResourceGroup : 'resourceGroupName' does not match expected pattern '^[-\w._()]+$'. At line:7 char:2 + Set-AzureRmResourceGroup -ResourceGroupName $RGName -Tag @{BUSINESS_ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmResourceGroup], ValidationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetA
zureResourceGroupCmdlet Set-AzureRmResourceGroup : 'resourceGroupName' does not match expected pattern '^[-\w._()]+$'. At line:7 char:2 + Set-AzureRmResourceGroup -ResourceGroupName $RGName -Tag @{BUSINESS_ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmResourceGroup], ValidationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetA
zureResourceGroupCmdlet Set-AzureRmResourceGroup : 'resourceGroupName' does not match expected pattern '^[-\w._()]+$'. At line:7 char:2 + Set-AzureRmResourceGroup -ResourceGroupName $RGName -Tag @{BUSINESS_ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmResourceGroup], ValidationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetA
zureResourceGroupCmdlet
If ($RGName.Tags -eq $null)
- this check doesnt make sense as you are not passing tags, so its always true. as for the error i have no clue, try debugging. or do something like:$rgname
right beforeset-azurermresourcegroup
– 4c74356b41