Tuesday, April 9, 2019

TFS Release Notes Write-Verbose continued

A while ago I posted a note on using the PowerShell Write-Verbose command for TFS logging when using the 'Execute PowerShell scripts on remote machine(s)' Task.

One of the issues we ran into was executing a command but we weren't getting the output.  In my case we were trying to call BizTalk's btstask.exe command in a PowerShell script, which was saved to the local remote server.  Every now and then we'd get an error, but it wasn't properly displaying in the TFS Release log.  So we would need to manually run the command by remoting into the server and then look at the output to verify what the issue was (typically we didn't delete existing suspended messages, so we couldn't update the application).

Initially I thought capturing the output via a variable would work, like so:
$myBtsTaskOutput = BTSTask.exe AddResource /Source:$srcPath /ApplicationName:$appName /Type:$resType /Overwrite /Destination:"%BTAD_InstallDir%\$outputFile" $gacOptions 

However, when I tried to capture the output by using:
Write-Verbose $myBtsTaskOutput -Verbose
the command would fail with an object error.  Even using .ToString() failed.


The proper way to get the output is to immediately cast the type of the variable to a string, like so:
[string]$myBtsTaskOutput = BTSTask.exe AddResource... 

Now the Write-Verbose command will give you the proper output.   Super simple :)