Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

Azure Powershell - api version is required for all requests

Pagina: 1
Acties:

Vraag


  • DragonChaser
  • Registratie: Mei 2013
  • Laatst online: 13-01-2023
Goedemiddag beste Tweakers,

Heb een PowerShell probleem waar ik al vier uur lang aan werk.

Probleem: collega heeft een verouderde .PFX cert van pre-prod verwijderd, is door zijn actie erachter gekomen dat pre-prod niet werkt zonder cert. SSL uitzetten via Azure werkt niet want de app is letterlijk geschreven om met SSL te werken vannuit code. Een nieuwere certificate nemen werkt niet want je kan geen custom domain toevoegen (we zijn geen domain owner).

Oplossing: de oude certificate van prod exporteren (.PFX) en uploaden op pre-prod.

Hoe: onderstaand script uitvoeren.
# $apiVersion = "2019-08-01"
# $apiVersion = ((Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Web).ResourceTypes | Where-Object ResourceTypeName -eq sites).ApiVersions

$appServiceCertificateName = "thumbprint##West Europe#"
$resourceGroupName = "sdemoproduction"
$azureLoginEmailId = "xxx.xxx@domain.com"
$subscriptionId = "e8277d4b-ac12-4a95-807a-e3ddbecc36aa"
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId $subscriptionId

$ascResource = Get-AzureRmResource -ResourceName $appServiceCertificateName -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.CertificateRegistration/certificateOrders" -ApiVersion $apiVersion[0]
$keyVaultId = ""
$keyVaultSecretName = ""
$certificateProperties=Get-Member -InputObject $ascResource.Properties.certificates[0] -MemberType NoteProperty
$certificateName = $certificateProperties[0].Name
$keyVaultId = $ascResource.Properties.certificates[0].$certificateName.KeyVaultId
$keyVaultSecretName = $ascResource.Properties.certificates[0].$certificateName.KeyVaultSecretName
$keyVaultIdParts = $keyVaultId.Split("/")
$keyVaultName = $keyVaultIdParts[$keyVaultIdParts.Length - 1]
$keyVaultResourceGroupName = $keyVaultIdParts[$keyVaultIdParts.Length - 5]
Set-AzureRmKeyVaultAccessPolicy -ResourceGroupName $keyVaultResourceGroupName -VaultName $keyVaultName -UserPrincipalName $azureLoginEmailId -PermissionsToSecrets get
$secret = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $keyVaultSecretName
$pfxCertObject=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @([Convert]::FromBase64String($secret.SecretValueText),"", [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfxPassword = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 50 | % {[char]$_})
$currentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
[Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
[io.file]::WriteAllBytes(".\appservicecertificate.pfx", $pfxCertObject.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $pfxPassword))
Write-Host "Created an App Service Certificate copy at: $currentDirectory\appservicecertificate.pfx"
Write-Warning "For security reasons, do not store the PFX password. Use it directly from the console as required."
Write-Host "PFX password: $pfxPassword"
Error: Get-AzureRmResource : The api-version query parameter (?api-version=) is required for all requests.

Get API version:
write-host $apiVersion
2018-11-01 2018-02-01 2017-08-01 2016-09-01 2016-08-01 2016-03-01 2015-11-01 2015-08-01-preview 2015-08-01 2015-07-01 2015-06-01 2015-05-01 2015-04-01 2015-02-01 2015-01-01 2014-11-01 2014-06-01 2014-04-01-preview 201
4-04-01
Get-Command Get-AzureRmResource

CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-AzureRmResource 6.7.3 AzureRM.Resources
Write-Host $apiVersion[0]
2018-11-01
Eerder ipv "-ApiVersion $apiVersion[0]" geprobeerd met -ApiVersion "2018-11-01", zoals te zien is, lijkt het erop dat de versie correct is. Get-AzureRmResource werkt, sterker nog de hele lijn geeft data "$ascResource = Get-AzureRmResource -ResourceName $appServiceCertificateName -ResourceGroupName $resourceGroupName".

[ Voor 4% gewijzigd door DragonChaser op 09-09-2019 14:19 ]

Alle reacties


  • DragonChaser
  • Registratie: Mei 2013
  • Laatst online: 13-01-2023
Ok schijnbaar kan je geen .PFX export doen zonder dat je keyvault abonnement hebt bij Azure, klopt dit?, kan iemand dit bevestigen?.