Azure / Azure/azure-powershell

Get-AzLog has duplicate properties in type which causes ConvertTo-Json to fail

Open
#11,353 11 comments 0 reactions 1 assignee Claimed by @VeryEarly View on GitHub
act-observability-squad Azure PS Team Monitor
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

## Description

`Get-AzLog` returns a type that has multiple of the same properties which causes `ConvertTo-Json` to fail.

## Steps to reproduce

```powershell
Get-AzLog -MaxRecord 10 | ConvertTo-Json
```
Gets you:
```
ConvertTo-Json: An item with the same key has already been added. Key: Authorization
```

This is because the type that `Get-AzLog` returns has 2 instances of an `Authorization` property along with a few other:

```pwsh
[Microsoft.Azure.Commands.Insights.OutputClasses.PSEventDataNoDetails].GetProperties().Name | Group-Object | select Count,Name | ? Count -gt 1

Count Name
----- ----
2 Authorization
2 Claims
2 EventTimestamp
2 HttpRequest
2 Level
2 Properties
2 SubmissionTimestamp
```

It looks like it's because the `PSEventData` type has an Authorization:
https://github.com/Azure/azure-powershell/blob/1bcbe7b1f7a3323ac98f7754ba03eeb6b45e79f2/src/Monitor/Monitor/OutputClasses/PSEventData.cs#L28

And `PSEventData`'s base class _also_ has an Authorization property:

```
PS > [Microsoft.Azure.Management.Monitor.Models.EventData].GetProperties().Name
Authorization
Claims
Caller
Description
Id
EventDataId
CorrelationId
```

I couldn't find the code for `Microsoft.Azure.Management.Monitor.Models.EventData`... but since `PSEventData` does not override `EventData` there are 2 properties that show up.

### Ask

There should be only one instance of these properties.

## Environment data

```
Name Value
---- -----
PSVersion 7.0.0-daily.20200317
PSEdition Core
GitCommitId 7.0.0-daily.20200317
OS Darwin 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

## Module versions

```
Directory: /Users/tyleonha/.local/share/powershell/Modules

ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 1.7.3 Az.Accounts Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave…}
Script 1.7.1 Az.Accounts Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave…}
Script 1.7.0 Az.Accounts Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave…}
Script 3.4.0 Az.Compute Core,Desk {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvailabilitySet…}
Script 1.4.0 Az.KeyVault Core,Desk {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, Stop-AzKeyVaultCertificateOperation, Get-AzKeyVaultCertificateOperation…}
Script 1.6.1 Az.Monitor Core,Desk {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile, Get-AzLogProfile…}
Script 1.10.0 Az.Resources Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignment…}
Script 1.6.0 Az.Websites Core,Desk {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppServicePlan…}
Script 1.3.1 Configuration Desk {Import-Configuration, Export-Configuration, Get-StoragePath, Add-MetadataConverter…}
Script 0.4.0 EditorServicesCommandSuite Desk {Add-CommandToManifest, Add-ModuleQualification, Add-PinvokeMethod, ConvertTo-FunctionDefinition…}
Script 0.0.7 Get-PSGoodFirstIssue Desk {Get-PSGoodFirstIssue, Get-PSHacktoberFestIssue}
Script 5.5.3 InvokeBuild Desk {Invoke-Build, Build-Checkpoint, Build-Parallel}
Binary 0.3.0 Microsoft.PowerShell.ConsoleGuiToo… Core {Out-ConsoleGridView, ocgv}
Script 0.2.0 Microsoft.PowerShell.GraphicalTools Core {Out-GridView, ogv}
Script 2.0.311 oh-my-posh Desk {Show-Colors, Show-ThemeColors, Show-ThemeSymbols, Get-Theme…}
Script 5.0.0 beta Pester Desk {Describe, Context, It, Should…}
Script 4.9.0 Pester Desk {Describe, Context, It, Should…}
Script 0.14.0 platyPS Desk {New-MarkdownHelp, Get-MarkdownMetadata, New-ExternalHelp, New-YamlHelp…}
Script 0.7.3 posh-git Desk {Invoke-NullCoalescing, Add-PoshGitToProfile, Get-PromptPath, Write-GitStatus…}
Script 1.7.4.4 PoshRSJob Desk {Get-RSJob, Receive-RSJob, Remove-RSJob, Start-RSJob…}
Script 0.8.0 PSHTML Desk {a, address, area, article…}
Binary 0.12.3 PSKubectl Core {ConvertFrom-KubeYaml, ConvertTo-KubeYaml, Get-KubeConfig, Get-KubeDeployment…}
Binary 0.11.1 PSKubectl Core {Compare-KubeResource, ConvertFrom-KubeYaml, Get-KubeConfig, Get-KubeDeployment…}
Script 2.0.0 rc2 PSReadLine Desk {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remove-PSReadLineKeyHandler, Get-PSReadLineOption…}
Script 0.2.0 PSStringTemplate Desk {New-StringTemplateGroup, Invoke-StringTemplate}
Binary 0.0.2 PSUnixUtilCompleters Core
Binary 3.0.1 PSWordCloud Core,Desk {New-WordCloud, wordcloud, wcloud, nwc}
Script 21.1.18179 SqlServer Desk {Add-RoleMember, Add-SqlAvailabilityDatabase, Add-SqlAvailabilityGroupListenerStaticIp, Add-SqlAzureAuthenticationContext…}
Script 1.2 TabExpansionPlusPlus Desk {Set-TabExpansionOption, Get-CommandWithParameter, Get-ArgumentCompleter, New-CommandTree…}

Directory: /Users/tyleonha/.powershell-daily/Modules

ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Manifest 1.2.5 Microsoft.PowerShell.Archive Desk {Compress-Archive, Expand-Archive}
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, Clear-ItemProperty, Join-Path…}
Manifest 7.0.0.0 Microsoft.PowerShell.Security Core {Get-Credential, Get-ExecutionPolicy, Set-ExecutionPolicy, ConvertFrom-SecureString…}
Manifest 7.0.0.0 Microsoft.PowerShell.Utility Core {Export-Alias, Get-Alias, Import-Alias, New-Alias…}
Script 1.4.6 PackageManagement Desk {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script 2.2.3 PowerShellGet Desk {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
Script 2.0.5 PSDesiredStateConfiguration Core {Configuration, New-DscChecksum, Get-DscResource, Invoke-DscResource}
Script 2.0.0 PSReadLine Desk {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remove-PSReadLineKeyHandler, Get-PSReadLineOption…}
Binary 2.0.3 ThreadJob Desk Start-ThreadJob
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.