I am by no means good at PowerShell and I know I will need this info again. I wanted to copy the secrets from one Vault (Dev) to another Vault (Stage) because most are going to be the same but a couple are different. I love clicking around in the Azure portal but this is the kind of thing prone to typo, especially since the Vault UI is one of the less fun.
I found this code here:
$secretNames = (Get-AzKeyVaultSecret -VaultName $sourceVaultName).Name
Set-AzKeyVaultSecret -VaultName $destVaultName -Name $_ `
-SecretValue (Get-AzKeyVaultSecret -VaultName $sourceVaultName -Name $_).SecretValue
But now I have a few issues:
running scripts is disabled on this system
Then, I unwisely but successfully ran this in Developer PowerShell for VS 2019 as an Administrator:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Connect-AzAccount : The term 'Connect-AzAccount' is not recognized as the name of a cmdlet, function, script file, or
I proceeded to learn that I needed an updated Nuget. I tried but I needed to do this:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
and then this:
Install-PackageProvider -Name NuGet
Install-Module Az -AllowClobber
then I ran the script and it worked.