question

PavanKumar-2003 avatar image
0 Votes"
PavanKumar-2003 asked JamesTran-MSFT commented

Azure Key Vault Set Secret from PowerShell- Pattern Match Exception

I am trying to bulk insert secrets to my Key Vault using power shell and Its throwing me Secret Validation exception saying Pattern Mismatch- ^[0-9a-zA-Z-]+$

But same secret, if i am doing manually in the portal, its working fine.

Need some insights and help.

windows-server-powershellazure-key-vault
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered PavanKumar-2003 commented

Please post the code you're using.

  1. Azure Powershell is outdated (i.e. it still works, but it's no longer supported)

  2. Use the newer Az module (azpsmigrate

  3. The secret is supposed to be a secure string. Is that what you're using? If not, see the help for the cmdlet and follow the examples given there.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

$inputfile = Import-Csv C:\BCP\inputcsv.csv

foreach($inp in $inputfile)

{

$Name = $inp.Name

$secretvalue = $inp.secretvalue

$Contenttype = $inp.Contenttype

$Tags = @{$inp.TagName = $inp.TagValue}


$Secret = ConvertTo-SecureString -String $secretvalue -AsPlainText -Force

set-azkeyvaultsecret LTLkeyVault -Name $Name -SecretValue $secret -ContentType $Contenttype -Tag $Tags

}

set-azkeyvaultsecret : 'secretName' does not match expected pattern '^[0-9a-zA-Z-]+$'.
At line:18 char:3
+ set-azkeyvaultsecret LTLkeyVault -Name $Name -SecretValue $secret ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzKeyVaultSecret], ValidationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.SetAzureKeyVaultSecret

0 Votes 0 ·
PavanKumar-2003 avatar image
0 Votes"
PavanKumar-2003 answered JamesTran-MSFT commented

Here is the code along with error i am using. Thanks for the response
$inputfile = Import-Csv C:\BCP\inputcsv.csv

foreach($inp in $inputfile)

{

$Name = $inp.Name

$secretvalue = $inp.secretvalue

$Contenttype = $inp.Contenttype

$Tags = @{$inp.TagName = $inp.TagValue}


$Secret = ConvertTo-SecureString -String $secretvalue -AsPlainText -Force

set-azkeyvaultsecret LTLkeyVault -Name $Name -SecretValue $secret -ContentType $Contenttype -Tag $Tags

}
set-azkeyvaultsecret : 'secretName' does not match expected pattern '^[0-9a-zA-Z-]+$'.
At line:18 char:3
+ set-azkeyvaultsecret LTLkeyVault -Name $Name -SecretValue $secret ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzKeyVaultSecret], ValidationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.SetAzureKeyVaultSecret


set-azkeyvaultsecret : 'secretName' does not match expected pattern '^[0-9a-zA-Z-]+$'.
At line:18 char:3
+ set-azkeyvaultsecret LTLkeyVault -Name $Name -SecretValue $secret ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzKeyVaultSecret], ValidationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.SetAzureKeyVaultSecret

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What's in the variable "$Name"? That value should contain only alphanumeric characters (0-9, a-z, A-Z, and minus sign). No spaces, punctuation, etc.

1 Vote 1 ·

@PavanKumar-2003
I just wanted to check in and see if you required additional assistance or if you were able to resolve this issue?

0 Votes 0 ·