@Puneet, Mithun , thank you for reaching out to us. Since you are getting error message as "Logging in to Azure...Connection not found." from your script, I suspect that value of $servicePrincipalConnection
is NULL. You can try connecting using a service principal account OR a Managed Service Identity OR Managed Service Identity login and ClientId OR certificate file depending on the host you are using. Further, to login without pop-up, using Service Principal
, please follow the accepted answer of this question on Stack Overflow. This provides a good and detailed answer about the use case.
You can find all the parameters and their definitions/descriptions in the corresponding links.
Further, to execute the Suspend-AzSqlDatabase to suspend a SQL Data Warehouse database, you can use below cmdlet in your script:
Suspend-AzSqlDatabase -ResourceGroupName "ABCD" -ServerName "XYZ" -DatabaseName "BCB"
But, there is another way to suspend which retrieves the database into the $database
object. It then pipes the object to Suspend-AzSqlDatabase
. The results are stored in the object resultDatabase
. The final command shows the results.:
$database = Get-AzSqlDatabase –ResourceGroupName "myResourceGroup" `
–ServerName "sqlpoolservername" –DatabaseName "mySampleDataWarehouse"
$resultDatabase = $database | Suspend-AzSqlDatabase
$resultDatabase
So, to sum it up, you can use below example for your use case:
try
{
"Logging in to Azure..."
# Write your login script here.
}
catch {
# Write your error handling script here.
}
$database = Get-AzSqlDatabase ResourceGroupName "ABCD" ServerName "XYZ" DatabaseName "BCB"
if($database){
if($database.Status -eq 'Online'){
$database | Suspend-AzSqlDatabase
Write-Output "The Data Warehouse was Active and paused now."
}else{
Write-Output "The Data Warehouse has already been paused."
}
}else{
Write-Output "The Data Warehouse does not exist."
}
Pls let me know if you have any follow-up questions.
-----------------------------------------------------------------------------------------------------------
Please "Accept the answer" and upvote if the information helped you. This will help us and others in the community as well.