diff --git a/src/KeyVault/KeyVault/ChangeLog.md b/src/KeyVault/KeyVault/ChangeLog.md index 6fa0b3ad62dd..96cd284f58d8 100644 --- a/src/KeyVault/KeyVault/ChangeLog.md +++ b/src/KeyVault/KeyVault/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Fixed a bug for `Get-AzKeyVaultSecret -IncludeVersions` when current version is disabled [#14740] * Displayed error code and message when updating purged secret [#14800] ## Version 3.4.2 diff --git a/src/KeyVault/KeyVault/Commands/GetAzureKeyVaultSecret.cs b/src/KeyVault/KeyVault/Commands/GetAzureKeyVaultSecret.cs index 7b00e5d5e653..df03cb72d57f 100644 --- a/src/KeyVault/KeyVault/Commands/GetAzureKeyVaultSecret.cs +++ b/src/KeyVault/KeyVault/Commands/GetAzureKeyVaultSecret.cs @@ -222,12 +222,7 @@ public override void ExecuteCmdlet() } else if (IncludeVersions) { - secret = DataServiceClient.GetSecret(VaultName, Name, string.Empty); - if (secret != null) - { - WriteObject(new PSKeyVaultSecretIdentityItem(secret)); - GetAndWriteSecretVersions(VaultName, Name, secret.Version); - } + GetAndWriteSecretVersions(VaultName, Name); } else if (InRemovedState) { @@ -271,14 +266,14 @@ private void GetAndWriteSecrets(string vaultName, string name) => }, (options) => KVSubResourceWildcardFilter(name, DataServiceClient.GetSecrets(options))); - private void GetAndWriteSecretVersions(string vaultName, string name, string currentSecretVersion) => + private void GetAndWriteSecretVersions(string vaultName, string name) => GetAndWriteObjects(new KeyVaultObjectFilterOptions { VaultName = vaultName, Name = name, NextLink = null }, - (options) => DataServiceClient.GetSecretVersions(options).Where(s => s.Version != currentSecretVersion)); + (options) => DataServiceClient.GetSecretVersions(options)); private void WriteSecret(PSKeyVaultSecret secret) {