I am to bulk update tags on specific resources listed in a CSV file. But get the error in the title. Any Idea How I Can Convert to string?
CSV Example:
ResourceName | ResourceGroup |
---|---|
vm10 | rg01 |
vm11 | rg02 |
Code:
$ResourceList = Import-Csv 'C:Users43263Desktopresources.csv'
$tags = @{"DeptNumber"="123G"; "OwnerEmail"="[email protected]"}
$getresource = Get-AzResource -Name $ResourceList.ResourceName -ResourceGroup $ResourceList.ResourceGroup
ForEach ($Resource in $ResourceList.ResourceName){
New-AzTag -ResourceId $getresource.id -Tag $tags
}
2
Answers
You need to loop over each row in your CSV and query each resource separately. Also, the property value you should use for
New-AzTag -ResourceId
is.ResourceId
not.Id
.I have reproduced in my environment and got expected results as below:
CSV File:
Then used below commands:
Output: