Reputation: 67
I am trying to create a RunBook that I can use for renaming an Azure DB for integration test purposes. I have had a look around and there are examples here but I have still not I have not been able to get any of them to work. I am using a Pay-as-you-go subscription and wish to use SQL logins.
I think its getting the correct SQLServerContext that is failing, though I cannot see see what I should be doing differently. I have create Automation credentials which just contain my SQL username and SQL password.
`
$sqlServerName = "servername"
$SqlCredentialAsset="AutomationCredentials"
$sqlCred = Get-AutomationPSCredential -Name $SqlCredentialAsset
$sqlContext = New-AzureSqlDatabaseServerContext -ServerName $sqlServerName -Credential $sqlCred
Set-AzureSqlDatabase -ConnectionContext $sqlContext -ServerName -DatabaseName "test" -NewDatabaseName "test_rename"`
EDIT
The steps I had to add to get Joys script to run from my current set up was:
Upvotes: 0
Views: 133
Reputation: 42163
I am trying to create a RunBook that I can use for renaming an Azure DB for integration test purposes.
If this is your final goal, just try the script in your powershell runbook, it works fine on my side.
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
Set-AzureRmSqlDatabase -ResourceGroupName "joywebapp" -ServerName "joydb" -DatabaseName "joydb3" -NewName "joydb2"
Upvotes: 1