Closed awsles closed 4 years ago
@lesterw1 Can you provide an example of cmdlet output (not debug output) in which logRetentionPolicy appears twice?
PS C:\PS1> Get-AzureRmLogProfile
WARNING: 11:23:21 - *** The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models
to Microsoft.Azure.Management.Monitor.Models in future releases.
WARNING: 11:23:21 - *** The namespace for output classes will be uniform for all classes in future releases to make it independent of
modifications in the model classes.
RetentionPolicy
Enabled : True
Days : 365
StorageAccountId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/azsu-rg-sapdevtest-monitoring/providers/Microsoft.Storage/storageAccounts/xxxxxxxxxxxxxxxxx
ServiceBusRuleId :
Locations
: global
: ukwest
Categories
: Write
: Delete
: Action
RetentionPolicy
Enabled : True
Days : 365
Id : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/microsoft.insights/logprofiles/default
Name : default
Type :
Location :
Tags :
PS C:\Users\watersl4\OneDrive - Centrica\Desktop\PS1> Get-AzureRmLogProfile | ConvertTo-json
WARNING: 11:23:47 - *** The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models
to Microsoft.Azure.Management.Monitor.Models in future releases.
WARNING: 11:23:47 - *** The namespace for output classes will be uniform for all classes in future releases to make it independent of
modifications in the model classes.
ConvertTo-json : An item with the same key has already been added.
At line:1 char:25
+ Get-AzureRmLogProfile | ConvertTo-json
+ ~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [ConvertTo-Json], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertToJsonCommand
PS C:\Users\watersl4\OneDrive - Centrica\Desktop\PS1>
It looks like this issue is coming from PSLogProfile
defining it's own implementation for the RetentionPolicy
property, which is already available in its base LogProfileResource
class. For some reason when this object is written to the output stream, it has both of these properties, and trying to convert the object to JSON
results in the above error. I'm not sure how or why both of these properties would be able to show up with the same name, but removing the added RetentionPolicy
property from the PSLogProfile
class above resolves the issue:
PS C:\> Get-AzLogProfile
StorageAccountId : /subscriptions/c9cbd920-c00c-427c-852b-8aaf38badaeb/resourceGroups/corm-test-rg/providers/Microsoft.
Storage/storageAccounts/cormteststorageaccount
ServiceBusRuleId :
Locations
: global
: westus2
Categories
: Delete
: Write
: Action
RetentionPolicy
Enabled : False
Days : 0
Id :
/subscriptions/c9cbd920-c00c-427c-852b-8aaf38badaeb/providers/microsoft.insights/logprofiles/corm-test-log-profile
Name : corm-test-log-profile
Type :
Location :
Tags :
PS C:\> Get-AzLogProfile | ConvertTo-Json
{
"StorageAccountId": "/subscriptions/c9cbd920-c00c-427c-852b-8aaf38badaeb/resourceGroups/corm-test-rg/providers/Microsoft.Storage/storageAccounts/cormteststorageaccount",
"ServiceBusRuleId": null,
"Locations": [
"global",
"westus2"
],
"Categories": [
"Delete",
"Write",
"Action"
],
"RetentionPolicy": {
"Enabled": false,
"Days": 0
},
"Id": "/subscriptions/c9cbd920-c00c-427c-852b-8aaf38badaeb/providers/microsoft.insights/logprofiles/corm-test-log-profile",
"Name": "corm-test-log-profile",
"Type": null,
"Location": null,
"Tags": null
}
@gucalder would you mind verifying if we need this extra RetentionPolicy
property that currently exists in PSLogProfile
, or if we can remove it? It doesn't appear this will be a breaking change since there still exists a RetentionPolicy
property on the output object with the same properties.
fixed in #11846
Description
Calling get-AzureRmLogProfile outputs a structure which contains RetentionPolicy twice. If the output is piped for ConvertTo-json cmdlet, that fails with a duplicate value error.
Note that there does NOT appear to be any issue with the return data type itself (Microsoft.Azure.Management.Monitor.Models.LogProfileResource).
Script/Steps for Reproduction
This needs to be performed on a subscription which has been configured with an Event Hub output for the Azure Activity log.
Module Version
Debug Output