Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get powershell script output in the deployment log for a vNext Release Template?

This blog post is the only thing I have found that comes close to the problem but it doesn't explain how to configure the Deploy Using PS/DSC to run with the verbose option: http://nakedalm.com/create-log-entries-release-management/

I can get this Agent-based Release Template to run the script:

Write-Debug "debug"
Write-Output "output"
Write-Verbose "verbose"
Write-Warning "warning"

The drilling down into deployment log for this release provides a log with the lines:

output
WARNING: warning

If I add -verbose to the Arguments field I also get a "VERBOSE: verbose" line in the log.

This is great, but I need the access to the System Variables ($Stage, $BuildNumber, etc). When I create a vNext template to run the same script (instructions are here: http://www.visualstudio.com/en-us/get-started/deploy-no-agents-vs.aspx), the log reports:

Copying recursively from \\vsalm\Drops2\TestBuild\TestBuild_20130710.3 to c:\Windows\DtlDownloads\my vnext component succeeded.

It is nice that this copying operation succeeded and all, but I'd like my script's output to be in this log as well. Does anyone have any idea about configuring a "Deploy Using PS/DSC" action so that the powershell script output is captured by Release Management?

like image 643
mrfelis Avatar asked Jan 14 '15 17:01

mrfelis


People also ask

Where are PowerShell scripts stored in Intune?

Win32app and PowerShell Scripts deployed are installed using the Intune Management Extension and there are log files to troubleshoot application deployment. The log files for the Intune Management Extension are located in C:\ProgramData\Microsoft\IntuneManagementExtension\Logs.

How often do PowerShell scripts run Intune?

5) Intune management extension agent will check with Intune every hour if any changes are made to the script or assigned any new script. Even this process will run on the machine after every reboot. 6) PowerShell scripts will time out after 30 minutes.

How do I call a PowerShell script from a function?

A function in PowerShell is declared with the function keyword followed by the function name and then an open and closing curly brace. The code that the function will execute is contained within those curly braces. The function shown is a simple example that returns the version of PowerShell.


2 Answers

For a vNext Release Template, try Write-Verbose with a -verbose switch if you want to see the powershell script output in the logs.

Eg. Write-Verbose "Some text" -verbose

like image 165
divyanshm Avatar answered Nov 14 '22 04:11

divyanshm


Allow me to shamelessly plug my own blog article about this subject, because I found that it's not easy to get a script that does everything right.

The following script skeleton ensures that stdout output is logged without empty lines, and that processing is halted on the first error, in which case both the error details and the stdout output upto that point are visible in MSRM:

function Deploy()
{
    $ErrorActionPreference = "Stop"

    try
    {
        #
        # Deployment actions go here.
        #
    }
    catch
    {
        # Powershell tracks all Exceptions that occured so far in $Error
        Write-Output "$Error"

        # Signal failure to MSRM:
        $ErrorActionPreference = "Continue"
        Write-Error "Error: $Error"
    }
}

pushd $Global:ApplicationPath
Deploy | Out-String | Write-Verbose -Verbose
popd

This is just the final result, the explanation behind it can be found here.

like image 33
Leon Bouquiet Avatar answered Nov 14 '22 04:11

Leon Bouquiet