1

How to execute a method that has Action<T> as a parameter in Powershell?

upgradeEngine.Configure(c => c.ScriptExecutor.ExecutionTimeoutSeconds = 15 * 60);

C# code:

var upgradeEngine = DeployChanges.To
    .SqlDatabase(connectionString)
    .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
    .LogToConsole();

//this line
upgradeEngine.Configure(c => c.ScriptExecutor.ExecutionTimeoutSeconds = 15 * 60);

//this line
upgradeEngine.Build();
Add-Type -Path (Join-Path -Path $currentPath -ChildPath 'x:\location\of\DbUp.dll')

$dbUp = [DbUp.DeployChanges]::To
$dbUp = [SqlServerExtensions]::SqlDatabase($dbUp, $connectionString)
$dbUp = [StandardExtensions]::WithScriptsFromFileSystem($dbUp, $scriptPath)
$dbUp = [StandardExtensions]::LogToConsole($dbUp)
$upgradeResult = $dbUp.Build().PerformUpgrade()

2
  • GSerg, there is no usage of argument from this method Commented Apr 16, 2017 at 10:23
  • I'm not sure what you mean by that, but the delegate accepts a parameter $i and uses it. Commented Apr 16, 2017 at 10:25

1 Answer 1

3

Construct a ScriptBlock with the appropriate signature and cast it as [Action[T]]

$delegate = [System.Action[DbUp.Builder.UpgradeConfiguration]]{
  param([DbUp.Builder.UpgradeConfiguration]$c)
  $c.ScriptExecutor.ExecutionTimeoutSeconds = 15 * 60
}
$DbUp.Configure($delegate)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.