0

I am trying to scale back a database after the restore operation has completed and am running into some problems. I am getting this exception and wonder if there is something in this script not supported by Azure Automation Workflows?

Parameter set cannot be resolved using the specified named parameters.

workflow insertflowname
{
  <#  
  .SYNOPSIS   

The purpose of this runbook is to demonstrate how to restore a particular database to a new database using an Azure Automation workflow. Then it is scaled back to Basic.

.NOTES  

#>  


# Specify Azure Subscription Name

$subName = 'insertsubscription name'

# Connect to Azure Subscription
Connect-Azure -AzureConnectionName $subName
Select-AzureSubscription -SubscriptionName $subName

# Define source databasename
$SourceDatabaseName = 'insert database name'

# Define source server
$SourceServerName = 'insert source server'

# Define destination server
$TargetServerName = 'insert destination server'

Write-Output "`$SourceServerName [$SourceServerName]"
Write-Output "`$TargetServerName [$TargetServerName]"
Write-Output "`$SourceDatabaseName [$SourceDatabaseName]"

Write-Output "Retrieving recoverable database details for database [$SourceDatabaseName] on server [$SourceServerName]."
$RecoverableDatabase = Get-AzureSqlRecoverableDatabase –ServerName $SourceServerName -DatabaseName $SourceDatabaseName
$TargetDatabaseName = "$SourceDatabaseName-$($RecoverableDatabase.LastAvailableBackupDate.ToString('O'))"
Write-Output "`$TargetDatabaseName [$TargetDatabaseName]"

Write-Output "Starting recovery of database [$SourceDatabaseName] to server [$TargetServerName] as database [$TargetDatabaseName]."
Start-AzureSqlDatabaseRecovery -SourceDatabase $RecoverableDatabase -TargetServerName $TargetServerName –TargetDatabaseName $TargetDatabaseName 

$PollingInterval = 10
Write-Output "Monitoring status of recovery operation, polling every [$PollingInterval] second(s)."
$KeepGoing = $true
while ($KeepGoing) {
    $operation = Get-AzureSqlDatabaseOperation -ServerName $TargetServerName -DatabaseName $TargetDatabaseName | Where-Object {$_.Name -eq "DATABASE RECOVERY"} | Sort-Object StartTime -Descending
    if ($operation) {
        $operation[0]
        if ($operation[0].State -eq "COMPLETED") { $KeepGoing = $false }
        if ($operation[0].State -eq "FAILED") {
            # Throw error
            $KeepGoing = $false
        }
    } else {
        # Throw error since something went wrong and object was not created
        # May want to have this retry a few times before giving up or at least notify somebody
        # since at this point the recovery has been kicked off and you don't want the database
        # restore to remain at the elevated service level.
        $KeepGoing = $false
    }
    if ($KeepGoing) { Start-Sleep -Seconds $PollingInterval }
}

if ($operation[0].State -eq "COMPLETED") {
    Write-Output "Setting service level for database [$TargetDatabaseName] on server [$TargetServerName] to Basic."
    $ServiceObjective = Get-AzureSQLDatabaseServiceObjective –ServerName $TargetServerName –ServiceObjectiveName "Basic"
    $ServiceObjective
    Set-AzureSqlDatabase –ServerName $TargetServerName –DatabaseName $TargetDatabaseName –Edition "Basic" –ServiceObjective $ServiceObjective -MaxSizeGB 2 –Force
   }
}

1 Answer 1

3

You are probably hitting the issue described here: https://social.msdn.microsoft.com/Forums/en-US/ce6412b8-5cce-4573-befb-6017924ce0d0/whereobject-fails-with-parameter-set-cannot-be-resolved-using-the-specified-named-parameters?forum=azureautomation

Summary: Use parameter names, don't rely on positional parameters, in PowerShell Workflow. In this case, you need to add the -FilterScript parameter name to Where-Object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.