Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.25k stars 3.85k forks source link

ResourceId is Invalid from Get-AzResource | Where-Object { } #13121

Closed pmantz closed 4 years ago

pmantz commented 4 years ago

Description

Trying to update tags on a resources array generated using a where-object filter, to pick only non tagged resources. Update-AzTag fails due to a null ResourceId, however if I filter resources based on name the command works fine. I've noticed that a lot of times the ResourceId is just trimmed, missing the last give or take 10 chars.

Steps to reproduce

$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}

Using $resources = Get-AzResource | Where-Object {$_.Name -eq "name"} works fine

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

Directory: C:\Users\Panagiotis\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     4.7.0                 Az                                  Core,Desk
Script     3.7.0                 Az                                  Core,Desk
Script     1.9.4                 Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzCo…
Script     1.7.4                 Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzCo…
Script     1.1.1                 Az.Advisor                          Core,Desk {Get-AzAdvisorRecommendation, Enable-Az…
Script     1.3.0                 Az.Aks                              Core,Desk {Get-AzAksCluster, New-AzAksCluster, Re…
Script     1.0.3                 Az.Aks                              Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Im…
Script     1.1.4                 Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspe…
Script     1.1.2                 Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspe…
Script     2.1.0                 Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToGateway, Add-A…
Script     1.4.0                 Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToProduct, Add-A…
Script     1.1.0                 Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, New-AzAppli…
Script     1.0.3                 Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, New-AzAppli…
Script     1.4.0                 Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Rem…
Script     1.3.6                 Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Rem…
Script     3.1.0                 Az.Batch                            Core,Desk {Remove-AzBatchAccount, Get-AzBatchAcco…
Script     2.0.2                 Az.Batch                            Core,Desk {Remove-AzBatchAccount, Get-AzBatchAcco…
Script     1.0.3                 Az.Billing                          Core,Desk {Get-AzBillingInvoice, Get-AzBillingPer…
Script     1.0.2                 Az.Billing                          Core,Desk {Get-AzBillingInvoice, Get-AzBillingPer…
Script     1.4.3                 Az.Cdn                              Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoU…
Script     1.4.2                 Az.Cdn                              Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoU…
Script     1.6.0                 Az.CognitiveServices                Core,Desk {Get-AzCognitiveServicesAccount, Get-Az…
Script     1.2.3                 Az.CognitiveServices                Core,Desk {Get-AzCognitiveServicesAccount, Get-Az…
Script     4.4.0                 Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvaila…
Script     3.6.0                 Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvaila…
Script     1.0.3                 Az.ContainerInstance                Core,Desk {New-AzContainerGroup, Get-AzContainerG…
Script     1.1.1                 Az.ContainerRegistry                Core,Desk {New-AzContainerRegistry, Get-AzContain…
Script     0.2.0                 Az.CosmosDB                         Core,Desk {Get-AzCosmosDBSqlContainer, Get-AzCosm…
Script     1.1.0                 Az.DataBoxEdge                      Core,Desk {Get-AzDataBoxEdgeJob, Get-AzDataBoxEdg…
Script     1.10.1                Az.DataFactory                      Core,Desk {Set-AzDataFactoryV2, Update-AzDataFact…
Script     1.7.0                 Az.DataFactory                      Core,Desk {Set-AzDataFactoryV2, Update-AzDataFact…
Script     1.0.2                 Az.DataLakeAnalytics                Core,Desk {Get-AzDataLakeAnalyticsDataSource, New…
Script     1.2.8                 Az.DataLakeStore                    Core,Desk {Get-AzDataLakeStoreTrustedIdProvider, …
Script     1.0.0                 Az.DataShare                        Core,Desk {New-AzDataShareAccount, Get-AzDataShar…
Script     1.1.0                 Az.DeploymentManager                Core,Desk {Get-AzDeploymentManagerArtifactSource,…
Script     1.0.0                 Az.DesktopVirtualization            Core,Desk {Disconnect-AzWvdUserSession, Get-AzWvd…
Script     1.0.2                 Az.DevTestLabs                      Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzD…
Script     1.1.2                 Az.Dns                              Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordCon…
Script     1.3.0                 Az.EventGrid                        Core,Desk {New-AzEventGridTopic, Get-AzEventGridT…
Script     1.2.3                 Az.EventGrid                        Core,Desk {New-AzEventGridTopic, Get-AzEventGridT…
Script     1.6.0                 Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHu…
Script     1.4.3                 Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHu…
Script     1.6.1                 Az.FrontDoor                        Core,Desk {New-AzFrontDoor, Get-AzFrontDoor, Set-…
Script     1.4.0                 Az.FrontDoor                        Core,Desk {New-AzFrontDoor, Get-AzFrontDoor, Set-…
Script     1.0.2                 Az.Functions                        Core,Desk {Get-AzFunctionApp, Get-AzFunctionAppAv…
Script     3.6.0                 Az.HDInsight                        Core,Desk {Get-AzHDInsightJob, New-AzHDInsightSqo…
Script     3.1.0                 Az.HDInsight                        Core,Desk {Get-AzHDInsightJob, New-AzHDInsightSqo…
Script     1.1.0                 Az.HealthcareApis                   Core,Desk {New-AzHealthcareApisService, Remove-Az…
Script     1.0.1                 Az.HealthcareApis                   Core,Desk {New-AzHealthcareApisService, Remove-Az…
Script     2.5.0                 Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubC…
Script     2.3.0                 Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubC…
Script     2.2.0                 Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKe…
Script     1.5.2                 Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKe…
Script     1.0.0                 Az.Kusto                            Core,Desk {Add-AzKustoClusterLanguageExtension, A…
Script     1.3.2                 Az.LogicApp                         Core,Desk {Get-AzIntegrationAccountAgreement, Get…
Script     1.1.3                 Az.MachineLearning                  Core,Desk {Move-AzMlCommitmentAssociation, Get-Az…
Script     1.1.0                 Az.Maintenance                      Core,Desk {Get-AzApplyUpdate, Get-AzConfiguration…
Script     1.1.0                 Az.ManagedServices                  Core,Desk {Get-AzManagedServicesAssignment, New-A…
Script     1.0.2                 Az.ManagedServices                  Core,Desk {Get-AzManagedServicesAssignment, New-A…
Script     1.0.2                 Az.MarketplaceOrdering              Core,Desk {Get-AzMarketplaceTerms, Set-AzMarketpl…
Script     1.1.1                 Az.Media                            Core,Desk {Sync-AzMediaServiceStorageKey, Set-AzM…
Script     2.1.0                 Az.Monitor                          Core,Desk {Get-AzMetricDefinition, Get-AzMetric, …
Script     1.6.2                 Az.Monitor                          Core,Desk {Get-AzMetricDefinition, Get-AzMetric, …
Script     3.4.0                 Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthentication…
Script     2.4.0                 Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthentication…
Script     1.1.1                 Az.NotificationHubs                 Core,Desk {Get-AzNotificationHub, Get-AzNotificat…
Script     2.3.0                 Az.OperationalInsights              Core,Desk {New-AzOperationalInsightsAzureActivity…
Script     1.3.4                 Az.OperationalInsights              Core,Desk {New-AzOperationalInsightsAzureActivity…
Script     1.3.1                 Az.PolicyInsights                   Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, …
Script     1.2.1                 Az.PolicyInsights                   Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, …
Script     1.1.2                 Az.PowerBIEmbedded                  Core,Desk {Remove-AzPowerBIWorkspaceCollection, G…
Script     1.1.1                 Az.PowerBIEmbedded                  Core,Desk {Remove-AzPowerBIWorkspaceCollection, G…
Script     1.0.3                 Az.PrivateDns                       Core,Desk {Get-AzPrivateDnsZone, Remove-AzPrivate…
Script     1.0.2                 Az.PrivateDns                       Core,Desk {Get-AzPrivateDnsZone, Remove-AzPrivate…
Script     2.12.1                Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, …
Script     2.8.0                 Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, …
Script     1.2.1                 Az.RedisCache                       Core,Desk {Remove-AzRedisCachePatchSchedule, New-…
Script     1.0.3                 Az.Relay                            Core,Desk {New-AzRelayNamespace, Get-AzRelayNames…
Script     2.5.1                 Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRole…
Script     1.13.0                Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRole…
Script     1.4.1                 Az.ServiceBus                       Core,Desk {New-AzServiceBusNamespace, Get-AzServi…
Script     2.2.0                 Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricClientCertificate, …
Script     2.0.1                 Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricClientCertificate, …
Script     1.2.0                 Az.SignalR                          Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSi…
Script     1.1.1                 Az.SignalR                          Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSi…
Script     2.10.0                Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryp…
Script     2.5.0                 Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryp…
Script     1.1.0                 Az.SqlVirtualMachine                Core,Desk {New-AzSqlVM, Get-AzSqlVM, Update-AzSql…
Script     2.6.0                 Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAcc…
Script     1.13.0                Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAcc…
Script     1.3.0                 Az.StorageSync                      Core,Desk {Invoke-AzStorageSyncCompatibilityCheck…
Script     1.2.3                 Az.StorageSync                      Core,Desk {Invoke-AzStorageSyncCompatibilityCheck…
Script     1.0.1                 Az.StreamAnalytics                  Core,Desk {Get-AzStreamAnalyticsFunction, Get-AzS…
Script     1.0.0                 Az.Support                          Core,Desk {Get-AzSupportService, Get-AzSupportPro…
Script     1.0.4                 Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndp…
Script     1.0.3                 Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndp…
Script     1.11.0                Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppService…
Script     1.8.0                 Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppService…

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   7.0.0.0               CimCmdlets                          Core      {Get-CimAssociatedInstance, Get-CimClas…
Manifest   1.2.5                 Microsoft.PowerShell.Archive        Desk      {Compress-Archive, Expand-Archive}
Manifest   7.0.0.0               Microsoft.PowerShell.Diagnostics    Core      {Get-WinEvent, New-WinEvent, Get-Counte…
Manifest   7.0.0.0               Microsoft.PowerShell.Host           Core      {Start-Transcript, Stop-Transcript}
Manifest   7.0.0.0               Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Get-Clipbo…
Manifest   7.0.0.0               Microsoft.PowerShell.Security       Core      {Get-Acl, Set-Acl, Get-PfxCertificate, …
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        Core      {Export-Alias, Get-Alias, Import-Alias,…
Manifest   7.0.0.0               Microsoft.WSMan.Management          Core      {Disable-WSManCredSSP, Enable-WSManCred…
Script     1.4.7                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-Package…
Script     2.2.4.1               PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…
Script     2.0.5                 PSDesiredStateConfiguration         Core      {Configuration, New-DscChecksum, Get-Ds…
Script     7.0.0.0               PSDiagnostics                       Core      {Disable-PSTrace, Disable-PSWSManCombin…
Script     2.0.2                 PSReadLine                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLi…
Binary     2.0.3                 ThreadJob                           Desk      Start-ThreadJob

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.0.1                 Microsoft.PowerShell.Operation.Val… Desk      {Get-OperationValidation, Invoke-Operat…
Script     1.0.0.0               Microsoft.SME.CredSspPolicy         Desk
Binary     1.0.0.1               PackageManagement                   Desk      {Find-Package, Get-Package, Get-Package…
Script     3.4.0                 Pester                              Desk      {Describe, Context, It, Should…}
Script     1.0.0.1               PowerShellGet                       Desk      {Install-Module, Find-Module, Save-Modu…
Script     2.0.0      beta2      PSReadline                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLi…

    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   1.0.0.0               AppBackgroundTask                   Core,Desk {Disable-AppBackgroundTaskDiagnosticLog…
Manifest   2.0.1.0               Appx                                Core,Desk {Add-AppxPackage, Get-AppxPackage, Get-…
Script     1.0.0.0               AssignedAccess                      Core,Desk {Clear-AssignedAccess, Get-AssignedAcce…
Manifest   1.0.0.0               BitLocker                           Core,Desk {Unlock-BitLocker, Suspend-BitLocker, R…
Manifest   2.0.0.0               BitsTransfer                        Core,Desk {Add-BitsFile, Complete-BitsTransfer, G…
Manifest   1.0.0.0               BranchCache                         Core,Desk {Add-BCDataCacheExtension, Clear-BCCach…
Manifest   1.0                   ConfigDefender                      Core,Desk {Get-MpPreference, Set-MpPreference, Ad…
Manifest   1.0                   Defender                            Core,Desk {Get-MpPreference, Set-MpPreference, Ad…
Manifest   1.0.2.0               DeliveryOptimization                Core,Desk {Delete-DeliveryOptimizationCache, Set-…
Manifest   1.0.0.0               DirectAccessClientComponents        Core,Desk {Disable-DAManualEntryPointSelection, E…
Script     3.0                   Dism                                Core,Desk {Add-AppxProvisionedPackage, Add-Window…
Manifest   1.0.0.0               DnsClient                           Core,Desk {Resolve-DnsName, Clear-DnsClientCache,…
Manifest   1.0.0.0               EventTracingManagement              Core,Desk {Start-EtwTraceSession, New-EtwTraceSes…
Manifest   1.0.0.0               HgsClient                           Core,Desk {Get-HgsAttestationBaselinePolicy, Get-…
Manifest   1.0.0.0               HgsDiagnostics                      Core,Desk {New-HgsTraceTarget, Get-HgsTrace, Get-…
Binary     2.0.0.0               Hyper-V                             Core,Desk {Add-VMAssignableDevice, Add-VMDvdDrive…
Binary     1.1                   Hyper-V                             Core,Desk {Add-VMDvdDrive, Add-VMFibreChannelHba,…
Manifest   2.0.0.0               International                       Core,Desk {Get-WinDefaultInputMethodOverride, Set…
Manifest   1.0.0.0               Kds                                 Core,Desk {Add-KdsRootKey, Get-KdsRootKey, Test-K…
Manifest   3.0.0.0               Microsoft.PowerShell.Diagnostics    Core,Desk {Get-WinEvent, Get-Counter, Import-Coun…
Manifest   1.0.0.0               Microsoft.PowerShell.LocalAccounts  Core,Desk {Add-LocalGroupMember, Disable-LocalUse…
Manifest   3.1.0.0               Microsoft.PowerShell.Management     Core,Desk {Add-Content, Clear-Content, Clear-Item…
Manifest   1.0                   MMAgent                             Core,Desk {Disable-MMAgent, Enable-MMAgent, Set-M…
Manifest   2.0.0.0               NetAdapter                          Core,Desk {Disable-NetAdapter, Disable-NetAdapter…
Manifest   1.0.0.0               NetConnection                       Core,Desk {Get-NetConnectionProfile, Set-NetConne…
Manifest   1.0.0.0               NetEventPacketCapture               Core,Desk {New-NetEventSession, Remove-NetEventSe…
Manifest   2.0.0.0               NetLbfo                             Core,Desk {Add-NetLbfoTeamMember, Add-NetLbfoTeam…
Manifest   1.0.0.0               NetNat                              Core,Desk {Get-NetNat, Get-NetNatExternalAddress,…
Manifest   2.0.0.0               NetQos                              Core,Desk {Get-NetQosPolicy, Set-NetQosPolicy, Re…
Manifest   2.0.0.0               NetSecurity                         Core,Desk {Get-DAPolicyChange, New-NetIPsecAuthPr…
Manifest   1.0.0.0               NetSwitchTeam                       Core,Desk {New-NetSwitchTeam, Remove-NetSwitchTea…
Manifest   1.0.0.0               NetTCPIP                            Core,Desk {Get-NetIPAddress, Get-NetIPInterface, …
Manifest   1.0.0.0               NetworkConnectivityStatus           Core,Desk {Get-DAConnectionStatus, Get-NCSIPolicy…
Manifest   1.0.0.0               NetworkSwitchManager                Core,Desk {Disable-NetworkSwitchEthernetPort, Ena…
Manifest   1.0.0.0               NetworkTransition                   Core,Desk {Add-NetIPHttpsCertBinding, Disable-Net…
Manifest   1.0.0.0               PcsvDevice                          Core,Desk {Get-PcsvDevice, Start-PcsvDevice, Stop…
Manifest   1.0.0.0               PKI                                 Core,Desk {Add-CertificateEnrollmentPolicyServer,…
Manifest   1.0.0.0               PnpDevice                           Core,Desk {Get-PnpDevice, Get-PnpDeviceProperty, …
Manifest   1.1                   PrintManagement                     Core,Desk {Add-Printer, Add-PrinterDriver, Add-Pr…
Binary     1.0.11                ProcessMitigations                  Core,Desk {Get-ProcessMitigation, Set-ProcessMiti…
Script     3.0                   Provisioning                        Core,Desk {Install-ProvisioningPackage, Export-Pr…
Manifest   1.0.0.0               ScheduledTasks                      Core,Desk {Get-ScheduledTask, Set-ScheduledTask, …
Manifest   2.0.0.0               SecureBoot                          Core,Desk {Confirm-SecureBootUEFI, Set-SecureBoot…
Manifest   2.0.0.0               SmbShare                            Core,Desk {Get-SmbShare, Remove-SmbShare, Set-Smb…
Manifest   2.0.0.0               SmbWitness                          Core,Desk {Get-SmbWitnessClient, Move-SmbWitnessC…
Manifest   1.0.0.0               StartLayout                         Core,Desk {Export-StartLayout, Import-StartLayout…
Manifest   2.0.0.0               Storage                             Core,Desk {Add-InitiatorIdToMaskingSet, Add-Parti…
Manifest   2.0.0.0               TLS                                 Core,Desk {New-TlsSessionTicketKey, Enable-TlsSes…
Manifest   1.0.0.0               TroubleshootingPack                 Core,Desk {Get-TroubleshootingPack, Invoke-Troubl…
Manifest   2.0.0.0               TrustedPlatformModule               Core,Desk {Get-Tpm, Initialize-Tpm, Clear-Tpm, Un…
Binary     2.1.639.0             UEV                                 Core,Desk
Manifest   2.0.0.0               VpnClient                           Core,Desk {Add-VpnConnection, Set-VpnConnection, …
Manifest   1.0.0.0               Wdac                                Core,Desk {Get-OdbcDriver, Set-OdbcDriver, Get-Od…
Manifest   2.0.0.0               Whea                                Core,Desk {Get-WheaMemoryPolicy, Set-WheaMemoryPo…
Manifest   1.0.0.0               WindowsDeveloperLicense             Core,Desk {Get-WindowsDeveloperLicense, Unregiste…
Script     1.0                   WindowsErrorReporting               Core,Desk {Enable-WindowsErrorReporting, Disable-…
Manifest   1.0.0.0               WindowsSearch                       Core,Desk {Get-WindowsSearchSetting, Set-WindowsS…
Manifest   1.0.0.0               WindowsUpdate                       Core,Desk Get-WindowsUpdateLog
Manifest   1.0.0.2               WindowsUpdateProvider               Core,Desk {Get-WUAVersion, Get-WULastInstallation…

    Directory: C:\Program Files\Intel\Wired Networking

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     23.5.2.1              IntelNetCmdlets                     Desk

Debug output

DEBUG: 2:08:24 μμ - UpdateAzureTagCommand begin processing with ParameterSet 'UpdateByResourceIdParameterSet'.
DEBUG: 2:08:24 μμ - using account id '..............'...
DEBUG: [Common.Authentication]: Authenticating using Account: '..............', environment: 'AzureCloud', tenant: '...................'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: '..............', Endpoint: 'https://login.microsoftonline.com/', ClientId: '...............', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClient
Uri: 'https://management.core.windows.net/', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using context with Authority 'https://login.microsoftonline.com/335836de-42ef-43a2-b145-348c2ee9ca5b/', CorrelationId: '00000000-0000-0000-0000-000000000000', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using AdalConfiguration with Domain: '..................', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: '...............', ClientRedirectUri: urn:ietf:wg:oauth:2.0:oob
DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2512213Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: ADAL PCL.CoreCLR with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2512446Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: ADAL PCL.CoreCLR with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2512605Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: === Token Acquisition started:
        CacheType: null
        Authentication Target: User
        , Authority Host: login.microsoftonline.com

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2512703Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: === Token Acquisition started:
        Authority: https://login.microsoftonline.com/335836de-42ef-43a2-b145-348c2ee9ca5b/
        Resource: https://management.core.windows.net/
        ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
        CacheType: null
        Authentication Target: User

DEBUG: [ADAL]: Verbose: 2020-10-01T11:08:24.2512892Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Verbose: 2020-10-01T11:08:24.2512965Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2517747Z: 00000000-0000-0000-0000-000000000000 - LoggerBase.cs: Deserialized 1 items to token cache.

DEBUG: [ADAL]: Verbose: 2020-10-01T11:08:24.2518065Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2020-10-01T11:08:24.2518148Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2518282Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: An item matching the requested resource was found in the cache

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2518360Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: An item matching the requested resource was found in the cache

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2518472Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: 36,75263592666666 minutes left until token in cache expires

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2518537Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: 36,75263592666666 minutes left until token in cache expires

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2518604Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: A matching item (access token or refresh token or both) was found in the cache

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2518679Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: A matching item (access token or refresh token or both) was found in the cache

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2518888Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: === Token Acquisition finished successfully. An access token was returned: Expiration Time: 1/10/2020 11:45:09 πμ +00:00

DEBUG: [ADAL]: Information: 2020-10-01T11:08:24.2518985Z: 373d258e-3198-49a0-b482-3e628ff50a0f - LoggerBase.cs: === Token Acquisition finished successfully. An access token was returned: Expiration Time: 1/10/2020 11:45:09 πμ +00:00Access Token Hash: 2RnkLUoYOjTQMRiKae8KXyUDHRmgf
IH+JnNPt7y/0WI=
         User id: .............

DEBUG: [Common.Authentication]: Renewing Token with Type: 'Bearer', Expiry: '10/01/2020 11:45:09 +00:00', MultipleResource? 'True', Tenant: '.................', UserId: '................'
DEBUG: [Common.Authentication]: User info for token DisplayId: '.....', Name: .........s, IdProvider: '.............', Uid: '.....................'
DEBUG: [Common.Authentication]: Checking token expiration, token expires '10/01/2020 11:45:09 +00:00' Comparing to '10/01/2020 11:08:24 +00:00' With threshold '00:05:00', calculated time until token expiry: '00:36:45.1566384'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PATCH

Absolute Uri:
https://management.azure.com//subscriptions/...../providers/Microsoft.ClassicStorage/storageAccounts/...../providers/Microsoft.Resources/tags/default?api-version=2020-06-01

Headers:
x-ms-client-request-id        : d44449b6-4f2d-4dec-97fe-d4e65e9ba507
Accept-Language               : en-US

Body:
{
  "operation": "Merge",
  "properties": {
    "tags": {
      "product": "...",
      "owner": "...",
    }
  }
}

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
NotImplemented

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-failure-cause            : gateway
x-ms-request-id               : 8a62648c-5bf3-4385-86ad-8849ea21b34b
x-ms-correlation-request-id   : 8a62648c-5bf3-4385-86ad-8849ea21b34b
x-ms-routing-request-id       : SWITZERLANDNORTH:20201001T110825Z:8a62648c-5bf3-4385-86ad-8849ea21b34b
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Thu, 01 Oct 2020 11:08:24 GMT
Connection                    : close

Body:
{
  "error": {
    "code": "ProviderError",
    "message": "null"
  }
}

Update-AzTag: null
DEBUG: AzureQoSEvent: CommandName - Update-AzTag; IsSuccess - False; Duration - 00:00:01.0924481;; Exception - Microsoft.Rest.Azure.CloudException: null
   at Microsoft.Azure.Management.ResourceManager.TagsOperations.UpdateAtScopeWithHttpMessagesAsync(String scope, TagsPatchResource parameters, Dictionary`2 customHeaders, CancellationToken cancellationToken)
   at Microsoft.Azure.Management.ResourceManager.TagsOperationsExtensions.UpdateAtScopeAsync(ITagsOperations operations, String scope, TagsPatchResource parameters, CancellationToken cancellationToken)
   at Microsoft.Azure.Management.ResourceManager.TagsOperationsExtensions.UpdateAtScope(ITagsOperations operations, String scope, TagsPatchResource parameters)
   at Microsoft.Azure.Commands.Tags.Client.TagsClient.UpdateTagAtScope(String scope, TagPatchOperation operation, IDictionary`2 parameters)
   at Microsoft.Azure.Commands.Tags.Tag.UpdateAzureTagCommand.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 2:08:25 μμ - UpdateAzureTagCommand end processing.

Error output

Message        : null
ServerMessage  : ProviderError: null (System.Collections.Generic.List`1[Microsoft.Rest.Azure.CloudError])
ServerResponse : {NotImplemented}
RequestMessage : {PATCH https://management.azure.com//subscriptions/8f986d9c-f3ff-4026-8a62-7b858cb1c71d/resourceGroups/Deployment/providers/Microsoft.ClassicStorage/storageAccounts/xmstagingdeployment/providers/Microsoft.Resources/tags/default?api-version=2020-06-01}
InvocationInfo : {Update-AzTag}
Line           : foreach ($resource in $resources) {Update-AzTag -ResourceId $resource.Id -Tag $tags -Operation Merge}
Position       : At line:1 char:36
                 + … resources) {Update-AzTag -ResourceId $resource.Id -Tag $tags -Operati …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace     :    at Microsoft.Azure.Management.ResourceManager.TagsOperations.UpdateAtScopeWithHttpMessagesAsync(String scope, TagsPatchResource parameters, Dictionary`2 customHeaders, CancellationToken cancellationToken)
                    at Microsoft.Azure.Management.ResourceManager.TagsOperationsExtensions.UpdateAtScopeAsync(ITagsOperations operations, String scope, TagsPatchResource parameters, CancellationToken cancellationToken)
                    at Microsoft.Azure.Management.ResourceManager.TagsOperationsExtensions.UpdateAtScope(ITagsOperations operations, String scope, TagsPatchResource parameters)
                    at Microsoft.Azure.Commands.Tags.Client.TagsClient.UpdateTagAtScope(String scope, TagPatchOperation operation, IDictionary`2 parameters)
                    at Microsoft.Azure.Commands.Tags.Tag.UpdateAzureTagCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
HistoryId      : 32

RequestId      : 422e5ad1-cc47-48ab-add0-cc0c5fd75131
Message        : null
ServerMessage  : ProviderError: null (System.Collections.Generic.List`1[Microsoft.Rest.Azure.CloudError])
ServerResponse : {NotImplemented}
RequestMessage : {PATCH https://management.azure.com//subscriptions/8f986d9c-f3ff-4026-8a62-7b858cb1c71d/resourceGroups/Barndoor-Logging/providers/Microsoft.ClassicStorage/storageAccounts/alltosplunkblobstorage/providers/Microsoft.Resources/tags/default?api-version=2020-06-01}
InvocationInfo : {Update-AzTag}
Line           : foreach ($resource in $resources) {Update-AzTag -ResourceId $resource.Id -Tag $tags -Operation Merge}
Position       : At line:1 char:36
                 + … resources) {Update-AzTag -ResourceId $resource.Id -Tag $tags -Operati …
                 +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace     :    at Microsoft.Azure.Management.ResourceManager.TagsOperations.UpdateAtScopeWithHttpMessagesAsync(String scope, TagsPatchResource parameters, Dictionary`2 customHeaders, CancellationToken cancellationToken)
                    at Microsoft.Azure.Management.ResourceManager.TagsOperationsExtensions.UpdateAtScopeAsync(ITagsOperations operations, String scope, TagsPatchResource parameters, CancellationToken cancellationToken)
                    at Microsoft.Azure.Management.ResourceManager.TagsOperationsExtensions.UpdateAtScope(ITagsOperations operations, String scope, TagsPatchResource parameters)
                    at Microsoft.Azure.Commands.Tags.Client.TagsClient.UpdateTagAtScope(String scope, TagPatchOperation operation, IDictionary`2 parameters)
                    at Microsoft.Azure.Commands.Tags.Tag.UpdateAzureTagCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
HistoryId      : 32

   HistoryId: 27

RequestId      : c1183bb0-29a7-4d71-a812-ca5578a25942
Message        : null
ServerMessage  : ProviderError: null (System.Collections.Generic.List`1[Microsoft.Rest.Azure.CloudError])
ServerResponse : {NotImplemented}
RequestMessage : {PATCH https://management.azure.com//subscriptions/8f986d9c-f3ff-4026-8a62-7b858cb1c71d/resourceGroups/xm-staging1-westeurope-mukr/providers/Microsoft.ClassicStorage/storageAccounts/xmstaging1westeurope4391/providers/Microsoft.Resources/tags/default?api-version=
                 2020-06-01}
InvocationInfo : {Update-AzTag}
Line           :                        Update-AzTag -ResourceId $resource.Id -Tag $tags -Operation Merge

Position       : At C:\Users\Panagiotis\Workspace\test-where.ps1:22 char:4
                 +             Update-AzTag -ResourceId $resource.Id -Tag $tags -Operati …
                 +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace     :    at Microsoft.Azure.Management.ResourceManager.TagsOperations.UpdateAtScopeWithHttpMessagesAsync(String scope, TagsPatchResource parameters, Dictionary`2 customHeaders, CancellationToken cancellationToken)
                    at Microsoft.Azure.Management.ResourceManager.TagsOperationsExtensions.UpdateAtScopeAsync(ITagsOperations operations, String scope, TagsPatchResource parameters, CancellationToken cancellationToken)
                    at Microsoft.Azure.Management.ResourceManager.TagsOperationsExtensions.UpdateAtScope(ITagsOperations operations, String scope, TagsPatchResource parameters)
                    at Microsoft.Azure.Commands.Tags.Client.TagsClient.UpdateTagAtScope(String scope, TagPatchOperation operation, IDictionary`2 parameters)
                    at Microsoft.Azure.Commands.Tags.Tag.UpdateAzureTagCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
HistoryId      : 27

Resolve-AzError: Input string was not in a correct format.
DEBUG: AzureQoSEvent: CommandName - Resolve-AzError; IsSuccess - False; Duration - 00:00:00.1227096;; Exception - System.FormatException: Input string was not in a correct format.
   at System.Text.StringBuilder.FormatError()
   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.Format(String format, Object[] args)
   at Microsoft.Azure.Commands.Profile.Errors.AzureRestExceptionRecord..ctor(CloudException exception, ErrorRecord record, Boolean inner)
   at Microsoft.Azure.Commands.Profile.Errors.ResolveError.HandleException(Exception exception, ErrorRecord record, Boolean inner)
   at Microsoft.Azure.Commands.Profile.Errors.ResolveError.HandleError(ErrorRecord record)
   at Microsoft.Azure.Commands.Profile.Errors.ResolveError.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 2:15:34 μμ - ResolveError end processing.
ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Wmengmsft, @MehaKaushik, @shurd, @anfeldma-ms

ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @armleads-azure.

pmantz commented 4 years ago

apparently the issue is with the resourceid values, for some reason even using them simply like this fails

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."}

at the same time Get-AzResource works just fine

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
pmantz commented 4 years ago

it seems the alert rules in question were associated with deleted resources that prevented tagging of the alert rules themselves.