How to get your PowerShell output to show up in Deployment Log

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.

Comments (4) -

  • If I use DSC scripts on premise I also don't get output in the logfiles. In VSO it works. Do you have any idea how I get rm to create log for DSC?
    • So you are using an on prem RM Server and your not getting the command output. But if you run the same script with RMO it is?
      • I have an on prem rm server and deploy to an existing environment. The only output I get is "Copying recursively from \\fileshare\drop\... to C:\Windows\DtlDownloads\...". A similar dsc configuration produces a perfect output in RMO in an azure environmwnt. Both scripts run fine - I can see the result in eventmgr... but a logile would be really helpful.
  • To make this work I found statements need to be like this:

    Write-Verbose "Database Update Complete" -Verbose

    Cheers - Graham

Add comment

Loading