Azure / Azure/azure-powershell

Can't run Get-AzSecurityTask at the subscription level

Open
#23,054 8 comments 0 reactions 0 assignees View on GitHub
act-codegen-extensibility-squad bug customer-reported Security Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### Description

Hi Team,

I am unable to run Get-AzSecurityTask on a Subscription.

```
$SubscriptionIDs = Get-AzSubscription

foreach ($sub in $SubscriptionIDs) {

$sub.Name
Set-AzContext -Subscription $sub | Out-null
Get-AzSecurityTask

}
```

This is the error I am getting, I have access to a lot of subscriptions and this error is occurring for all of them.

![image](https://github.com/Azure/azure-resource-manager-schemas/assets/23202775/4878fddd-2584-4355-9428-cac8877274e9)

Looks like it was a bug that existed previously. [issue](https://github.com/Azure/azure-powershell/issues/9755)

Let me know if you would like anymore details.

Kind Regards,
Daniel Tanious

### Issue script & Debug output

```PowerShell
Issue Script:

$SubscriptionIDs = Get-AzSubscription

foreach ($sub in $SubscriptionIDs) {

$sub.Name
Set-AzContext -Subscription $sub | Out-null
Get-AzSecurityTask

}
```

Debug Output:
Can't provide as it contains to much sensitive data.
```

### Environment data

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

### Module versions

```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.12.5 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 1.4.0 Az.Security {Add-AzSecurityAdaptiveNetworkHardening, Add-AzSecuritySqlVulnerabilityAssessmentBaseline, Confirm…
Script 5.9.0 Az.Storage {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManagementPolicyAction, Add-AzStorageAccou…
Manifest 2.1.0 AzTable {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}
```

### Error output

```PowerShell
Message : The given key 'policyName' was not present in the dictionary.
StackTrace : at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.Azure.Commands.Security.Models.Tasks.PSSecurityTaskConverters.ConvertToPSType(SecurityTask value)
at Microsoft.Azure.Commands.Security.Models.Tasks.PSSecurityTaskConverters.<>c.b__1_0(SecurityTask task)
at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()
at Microsoft.Azure.Commands.Security.Models.Tasks.PSSecurityTaskConverters.ConvertToPSType(IEnumerable`1 value)
at Microsoft.Azure.Commands.Security.Cmdlets.Tasks.GetTasks.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.Collections.Generic.KeyNotFoundException
InvocationInfo : {Get-AzSecurityTask}
Line : Get-AzSecurityTask

Position : At untitled:Untitled-1:42 char:5
+ Get-AzSecurityTask
+ ~~~~~~~~~~~~~~~~~~
HistoryId : 1
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the subscription-level Get-AzSecurityTask command from the issue script, then inspect PSSecurityTaskConverters.ConvertToPSType and GetTasks.ExecuteCmdlet, which appear in the stack trace. Compare the returned task data with the converter's expected fields and verify that the command completes without the policyName exception across subscriptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, powershell
Domain
cloud, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.