FormatVersion 2 switch not working in Set-AzNetworkWatcherConfigFlowLog
Description
When using the Set-AzNetworkWatcherConfigFlowLog cmdlet, I am unable to get the -FormatVersion 2 switch to set the NSG flow logs to Version 2. Running the command against any NSG will set Version 1. I verified that I can set this in the portal without issue. I have tested this with all versions of Az.Network 1.0.0 and up to the latest release.
Steps to reproduce
PS C:> $NW = Get-AzNetworkWatcher -ResourceGroupName NetworkWatcherRg -Name NetworkWatcher_westcentralus PS C:> $nsg = Get-AzNetworkSecurityGroup -ResourceGroupName NSGRG -Name appNSG PS C:> $storageId = "/subscriptions/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb/resourceGroups/NSGRG/providers/Microsoft.Storage/storageAccounts/examplestorageaccount"
PS C:> Set-AzNetworkWatcherConfigFlowLog -NetworkWatcher $NW -TargetResourceId $nsg.Id -EnableFlowLog $true -StorageAccountId $storageID -FormatVersion 2
Environment data
Name Value
PSVersion 5.1.17134.590
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.590
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Module versions
ModuleType Version Name ExportedCommands
Script 1.4.0 Az.Accounts {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave...}
Script 1.0.1 Az.Aks {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCredential...}
Script 1.0.2 Az.AnalysisServices {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServicesServer, Get-AzAnalysisServicesServer, Remove-AzAnalysisServicesServer...}
Script 1.0.0 Az.ApiManagement {Add-AzApiManagementRegion, Get-AzApiManagementSsoToken, New-AzApiManagementCustomHostnameConfiguration, New-AzApiManagementSystemCertificate...}
Script 1.0.0 Az.ApplicationInsights {Get-AzApplicationInsights, New-AzApplicationInsights, Remove-AzApplicationInsights, Set-AzApplicationInsightsPricingPlan...}
Script 1.2.0 Az.Automation {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybridWorkerGroup, Get-AzAutomationJobOutputRecord, Import-AzAutomationDscNodeConfiguration...}
Script 1.0.0 Az.Batch {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAccountKeys, New-AzBatchAccount...}
Script 1.0.0 Az.Billing {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollmentAccount, Get-AzConsumptionBudget...}
Script 1.1.0 Az.Cdn {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfile, Remove-AzCdnProfile...}
Script 1.0.1 Az.CognitiveServices {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveServicesAccountSkus, Get-AzCognitiveServicesAccountType...}
Script 1.6.0 Az.Compute {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvailabilitySet...}
Script 1.0.0 Az.ContainerInstance {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzContainerGroup, Get-AzContainerInstanceLog}
Script 1.0.1 Az.ContainerRegistry {New-AzContainerRegistry, Get-AzContainerRegistry, Update-AzContainerRegistry, Remove-AzContainerRegistry...}
Script 1.0.2 Az.DataFactory {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFactoryV2, Remove-AzDataFactoryV2...}
Script 1.0.0 Az.DataLakeAnalytics {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalyticsCatalogCredential, Remove-AzDataLakeAnalyticsCatalogCredential, Set-AzDataLakeAnalyticsCatalogCredential...}
Script 1.1.0 Az.DataLakeStore {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreFirewallRule, Set-AzDataLakeStoreTrustedIdProvider...}
Script 1.0.0 Az.DevTestLabs {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolicy, Get-AzDtlAutoStartPolicy, Get-AzDtlVMsPerLabPolicy...}
Script 1.0.0 Az.Dns {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet...}
Script 1.1.0 Az.EventGrid {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGridTopic, New-AzEventGridTopicKey...}
Script 1.0.1 Az.EventHub {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzEventHubNamespace, Remove-AzEventHubNamespace...}
Script 1.0.0 Az.HDInsight {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wait-AzHDInsightJob, New-AzHDInsightStreamingMapReduceJobDefinition...}
Script 1.0.2 Az.IotHub {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-AzIotHubConnectionString, Get-AzIotHubJob...}
Script 1.1.0 Az.KeyVault {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, Stop-AzKeyVaultCertificateOperation, Get-AzKeyVaultCertificateOperation...}
Script 1.2.1 Az.LogicApp {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccountAssembly, Get-AzIntegrationAccountBatchConfiguration, Get-AzIntegrationAccountCallbackUrl...}
Script 1.0.0 Az.MachineLearning {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssociation, Get-AzMlCommitmentPlanUsageHistory, Remove-AzMlCommitmentPlan...}
Script 1.0.0 Az.MarketplaceOrdering {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script 1.0.0 Az.Media {Sync-AzMediaServiceStorageKeys, Set-AzMediaServiceKey, Get-AzMediaServiceKeys, Get-AzMediaServiceNameAvailability...}
Script 1.0.1 Az.Monitor {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile, Get-AzLogProfile...}
Script 1.1.0 Az.Network {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthenticationCertificate, New-AzApplicationGatewayAuthenticationCertificate, Remove-AzApplicationGatewayAuthenticationCertificate...}
Script 1.0.0 Az.Network {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthenticationCertificate, New-AzApplicationGatewayAuthenticationCertificate, Remove-AzApplicationGatewayAuthenticationCertificate...}
Script 1.0.0 Az.NotificationHubs {Get-AzNotificationHub, Get-AzNotificationHubAuthorizationRules, Get-AzNotificationHubListKeys, Get-AzNotificationHubPNSCredentials...}
Script 1.1.0 Az.OperationalInsights {New-AzOperationalInsightsAzureActivityLogDataSource, New-AzOperationalInsightsCustomLogDataSource, Disable-AzOperationalInsightsLinuxCustomLogCollection, Disable-AzOperationalInsightsIISLogCollection...}
Script 1.0.0 Az.PolicyInsights {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediation...}
Script 1.0.0 Az.PowerBIEmbedded {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollectionAccessKeys, Get-AzPowerBIWorkspace...}
Script 1.2.0 Az.RecoveryServices {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServicesVault, Get-AzRecoveryServicesVaultSettingsFile, New-AzRecoveryServicesVault...}
Script 1.0.0 Az.RedisCache {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheScheduleEntry, Get-AzRedisCachePatchSchedule, New-AzRedisCachePatchSchedule...}
Script 1.0.0 Az.Relay {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNamespace, Remove-AzRelayNamespace...}
Script 1.2.1 Az.Resources {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignment...}
Script 1.0.0 Az.ServiceBus {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set-AzServiceBusNamespace, Remove-AzServiceBusNamespace...}
Script 1.0.1 Az.ServiceFabric {Add-AzServiceFabricApplicationCertificate, Add-AzServiceFabricClientCertificate, Add-AzServiceFabricClusterCertificate, Add-AzServiceFabricNode...}
Script 1.0.2 Az.SignalR {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSignalRKey...}
Script 1.7.0 Az.Sql {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptionActivity, Set-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseUpgradeHint...}
Script 1.1.0 Az.Storage {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAccountKey...}
Script 1.0.0 Az.StreamAnalytics {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDefaultFunctionDefinition, New-AzStreamAnalyticsFunction, Remove-AzStreamAnalyticsFunction...}
Script 1.0.1 Az.TrafficManager {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTrafficManagerCustomHeaderFromEndpoint, Add-AzTrafficManagerCustomHeaderToProfile, Remove-AzTrafficManagerCustomHeaderFromProfile...}
Script 1.1.2 Az.Websites {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppServicePlan...}
Debug output
DEBUG: 9:49:29 AM - SetAzureNetworkWatcherConfigFlowLogCommand begin processing with ParameterSet 'SetFlowlogByResourceWithoutTA'. DEBUG: 9:49:29 AM - using account id '(removed)'... DEBUG: [Common.Authentication]: Authenticating using Account: '(removed)', environment: 'AzureCloud', tenant: '(removed)' DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: c47ff952-410a-422e-b55f-52c225d57aa3 - AcquireTokenHandlerBase.cs: === Token Acquisition started: Authority: https://login.microsoftonline.com/7cf48d45-3ddb-4389-a9c1-c115526eb52e/ Resource: https://management.core.windows.net/ ClientId: 1950a258-227b-4e31-a9cf-717495945fc2 CacheType: null Authentication Target: User
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: - TokenCache.cs: Deserialized 2 items to token cache.
DEBUG: [ADAL]: Verbose: 3/27/2019 1:49:29 PM: c47ff952-410a-422e-b55f-52c225d57aa3 - TokenCache.cs: Looking up cache for a token...
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: c47ff952-410a-422e-b55f-52c225d57aa3 - TokenCache.cs: An item matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: c47ff952-410a-422e-b55f-52c225d57aa3 - TokenCache.cs: 45.3598063316667 minutes left until token in cache expires
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: c47ff952-410a-422e-b55f-52c225d57aa3 - TokenCache.cs: A matching item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: c47ff952-410a-422e-b55f-52c225d57aa3 - AcquireTokenHandlerBase.cs: === Token Acquisition finished successfully. An access token was retuned: Access Token Hash: 4CNqyBIezQ0pPIG5yuZ9wMURAVkeXmU03WwVqQEWodo= Expiration Time: 3/27/2019 2:34:51 PM +00:00 User Hash: //9wtJRd579oMiJXFa3enEeHXE1fbzUrt38XhS62JkY=
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: fcd033d5-dcd5-4fde-8e09-c36992d5cf61 - AcquireTokenHandlerBase.cs: === Token Acquisition started: Authority: https://login.microsoftonline.com/7cf48d45-3ddb-4389-a9c1-c115526eb52e/ Resource: https://management.core.windows.net/ ClientId: 1950a258-227b-4e31-a9cf-717495945fc2 CacheType: null Authentication Target: User
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: - TokenCache.cs: Deserialized 2 items to token cache.
DEBUG: [ADAL]: Verbose: 3/27/2019 1:49:29 PM: fcd033d5-dcd5-4fde-8e09-c36992d5cf61 - TokenCache.cs: Looking up cache for a token...
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: fcd033d5-dcd5-4fde-8e09-c36992d5cf61 - TokenCache.cs: An item matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: fcd033d5-dcd5-4fde-8e09-c36992d5cf61 - TokenCache.cs: 45.3597402666667 minutes left until token in cache expires
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: fcd033d5-dcd5-4fde-8e09-c36992d5cf61 - TokenCache.cs: A matching item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Information: 3/27/2019 1:49:29 PM: fcd033d5-dcd5-4fde-8e09-c36992d5cf61 - AcquireTokenHandlerBase.cs: === Token Acquisition finished successfully. An access token was retuned: Access Token Hash: 4CNqyBIezQ0pPIG5yuZ9wMURAVkeXmU03WwVqQEWodo= Expiration Time: 3/27/2019 2:34:51 PM +00:00 User Hash: //9wtJRd579oMiJXFa3enEeHXE1fbzUrt38XhS62JkY=
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method: POST
Absolute Uri: https://management.azure.com/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/NetworkWatcherRG/providers/Microsoft.Network/networkWatchers/NetworkWatcher_westcentralus/configureFlowLog?api-version=2018-11-01
Headers: x-ms-client-request-id : 8c38e669-c55d-4c95-8c8a-735fecbb501e accept-language : en-US
Body: { "targetResourceId": "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/testtesttest/providers/Microsoft.Network/networkSecurityGroups/testtesttest", "properties": { "storageId": "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/diagnostics/providers/Microsoft.Storage/storageAccounts/59ec1ec4diag", "enabled": true, "retentionPolicy": { "days": 0, "enabled": false } } }
DEBUG: ============================ HTTP RESPONSE ============================
Status Code: OK
Headers: Pragma : no-cache x-ms-request-id : 09245e8a-758d-4aca-a214-223b8628eec1 x-ms-correlation-request-id : 4aae1a2d-765a-47ac-85f3-9758e9e74b8c Strict-Transport-Security : max-age=31536000; includeSubDomains Cache-Control : no-cache Server : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0 x-ms-ratelimit-remaining-subscription-writes: 1199 x-ms-routing-request-id : NORTHCENTRALUS:20190327T134933Z:4aae1a2d-765a-47ac-85f3-9758e9e74b8c X-Content-Type-Options : nosniff Date : Wed, 27 Mar 2019 13:49:32 GMT
Body: { "targetResourceId": "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/testtesttest/providers/Microsoft.Network/networkSecurityGroups/testtesttest", "properties": { "storageId": "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/diagnostics/providers/Microsoft.Storage/storageAccounts/59ec1ec4diag", "enabled": true, "retentionPolicy": { "days": 0, "enabled": false }, "format": { "type": "JSON", "version": 1 } } }
"targetResourceId": "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/testtesttest/providers/Microsoft.Network/networkSecurityGroups/testtesttest" "storageId": "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/diagnostics/providers/Microsoft.Storage/storageAccounts/59ec1ec4diag" Enabled : True RetentionPolicy : { "Days": 0, "Enabled": false } FlowAnalyticsConfiguration : null
DEBUG: AzureQoSEvent: CommandName - Set-AzNetworkWatcherConfigFlowLog; IsSuccess - True; Duration - 00:00:03.3302090; Exception - ; DEBUG: Finish sending metric. DEBUG: 9:49:33 AM - SetAzureNetworkWatcherConfigFlowLogCommand end processing. DEBUG: 9:49:33 AM - SetAzureNetworkWatcherConfigFlowLogCommand end processing.
Error output
No errors
@irrogozh Looks like the Format Version is not being sent in the request. Can you please take a look?
@markcowl , I reassigned this issue to Wen @zwswim , who was working on this cmdlet.
It looks like currently, we have problem if the user only give -FormatVersion but not give -FormatType. Still looking for the root causing. To get around the problem, Please ask user to add -FormatType when they call Set-AzNetworkWatcherConfigFlowLog
Set-AzNetworkWatcherConfigFlowLog -FormatVersion '2' -FormatType Json -NetworkWatcher $NW -TargetResourceId $nsg.Id -EnableFlowLog $true -StorageAccountId $storageID
PR https://github.com/Azure/azure-powershell/pull/8902 to fix the bug
Thanks zwswim. This workaround of adding -FormatType does resolve this issue.
Confirm adding the -FormatType does resolve our issues. We are running from Azure DevOps powershell task ver 4.*, most recent release of powershell and it is still affected by this bug. The workaround works for us. Thanks all.
@KyMidd are you still experiencing this issue? We believe the fix went into effect after late June. Can you please update if it's still reproducing?
@KarenHammons: We haven't tested again, and likely won't - the workaround is working perfectly. Thanks for getting the root cause resolved! kyler
good deal