Problem:
I wrote some custom PowerShell that calls an exe but the
output is not being shown in the Release Management Deployment Log.
Solution:
Wrap your PowerShell in a function and pass the -Verbose switch.
Explanation:
When Release Management runs your PowerShell it will display
anything written with Write-Verbose in the Command Output section of the
Deployment Log. However, the output of exe’s run within a PowerShell script
are written to stdout or stderr. You have to capture the output and write it
to Write-Verbose yourself.
function deploy_db
{
[CmdletBinding()]
param()
Write-Verbose
"Updating Database"
$output = & 'C:\Program Files (x86)\Microsoft SQL
Server\120\DAC\bin\SqlPackage.exe' /Action:Publish
/SourceFile:$applicationPath\$FileName
/TargetConnectionString:"Data Source=$SqlServer;User
ID=$UserID;Password=$Password;Initial
Catalog=$DatabaseName" 2>&1
Write-Verbose
"$output"
Write-Verbose
"Database Update Complete"
}
deploy_db -Verbose
In the sample above we are capturing the output of the call
to SqlPackage.exe into $output. The 2>&1 is redirecting stderr to
stdout so we will capture any errors as well. Next we use Write-Verbose to
write any values we want to appear in the Command Output of the Deployment
Log. Finally we call ourselves passing in -Verbose.