git-azure icon indicating copy to clipboard operation
git-azure copied to clipboard

Set-AzureRmResource returns " The pipeline has been stopped." When trying to add tags in hashtable

Open Yanivro opened this issue 8 years ago • 2 comments

Trying to handle adding tags while not overwriting the current tags on the resource by adding them to the $tags hash-table like shown here:

https://azure.microsoft.com/en-us/documentation/articles/resource-group-using-tags/

Same error in both Azure Automation Runbook and my station.

updates all packages and they work fine.

It works on Set-AzureRmResourcegroup but not on Set-AzureRmResource

Error message:

Set-AzureRmResource : The pipeline has been stopped.
At line:1 char:1
+ Set-AzureRmResource -ResourceId $rm.ResourceGroupName -Tag $tags
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmResource], PipelineStoppedException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzureResourceCmdlet

Set-AzureRmResource : MissingSubscription : The request did not have a provided subscription. All requests must have an asso
ciated subscription Id.
At line:1 char:1
+ Set-AzureRmResource -ResourceId $rm.ResourceGroupName -Tag $tags
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmResource], ErrorResponseMessageException
    + FullyQualifiedErrorId : MissingSubscription,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzureR 
   esourceCmdlet

Code:

$naming = Import-Csv "E:\tags.csv"

foreach ($name in $naming){

$nameContains=$name.nameConvention
$rms=Find-AzureRmResource -ResourceNameContains $nameContains -ExpandProperties


foreach($rm in $rms){

        $id=$rm.ResourceId
        $tags=$rm.tags


                if ($rm.name -Match $name.nameConvention ){
                    $value=$name.tag
                    if($value){

                if($tags){
                    $exist=$false
                    foreach ($tag in $tags){    
                        if ($tag.Values -contains "Customer"){
                            $exist=$true }}
                    if ($exist -eq $false){

foreach($newtag in $tags){

$tags| get-member

}

$newthing=@( @{ Name="Customer"; Value=$value})

                    $tags += @{ Name="Customer"; Value=$value }

                    Set-AzureRmResource -ResourceName $rm.ResourceName -ResourceType $rm.ResourceType -Tag $tags 


                }} else {

                    $value=$name.tag

                    Set-AzureRmResource -ResourceId $id -Tag @( @{ Name="Customer"; Value=$value ; $tags. }) -Force

                }

            }

            }


    }
}

Yanivro avatar May 17 '16 14:05 Yanivro

It seems to have something to do with properties that have "hidden-link" tag in them.

Yanivro avatar May 17 '16 15:05 Yanivro

did you ever resolve your issue?

ikiris04 avatar Aug 07 '17 21:08 ikiris04