我想从Azure VM执行Powershell脚本以获取其当前的公共IP地址(并将此地址写入环境变量以供应用程序使用)。
我的问题是验证Azure Powershell环境的最佳方法是什么?在AWS凭据创建时,会将其“烘焙”到实例中。是否与Azure虚拟机相同?
答案 0 :(得分:1)
您可以使用Publish Settings file中包含的管理证书并自行“烘焙”
Import-AzurePublishSettingsFile –PublishSettingsFile C:\Store\my.publishsettings
如果您已经拥有管理证书,可以将其存储在您的虚拟机中,并将use it存储在PS中
# Get management certificate from personal store
$certificate = Get-Item cert:\\CurrentUser\My\$CertificateThumbprint
if ($certificate -eq $null) {
throw “Management certificate for $SubscriptionName was not found in the users personal certificate store. Check thumbprint or install certificate”
}
# Set subscription profile
Set-AzureSubscription -SubscriptionName $SubscriptionName -SubscriptionId $SubscriptionId -Certificate $certificate
# Select subscription as the current context
Select-AzureSubscription -SubscriptionName $SubscriptionName