none
About the destination of the Write-Output RRS feed

  • Question

  • I want to write-out a json file when run the runbook.

    i used the code below but i don't know where the json file is saved.

    $date = Get-Date -format "yyyyMMddHHMMss"
    $logFileName = ".\HealthcheckResult_"+ $date +".json"
    Write-Output "Datetime,TestType,PermissionFlag,TestResult,Message" | Out-File -FilePath $logFileName -Append -Encoding string

    thank you in advance

    Tuesday, September 24, 2019 9:40 AM

All replies

  • Normally when you want to store files temporarily when executing the runbook, you can store them at $env:TEMP and retrieve  from them.Here is an example .

    $logFileName = New-Item "$env:TEMP\test1.html" -ItemType File
    Set-Content "$env:TEMP\test1.html" '<html>Welcome to Azure</html>'
    
    Write-Output "Datetime,TestType,PermissionFlag,TestResult,Message" | Out-File -FilePath $logFileName -Append -Encoding string 
    Get-Content "$env:TEMP\test1.html" 

    And also whenever, you use output stream, all the content is written to job history. To retrieve the output, you can use Get-AzAutomationJobOutput command.

    For more information, please refer this article.

    Hope this helps!

    Wednesday, September 25, 2019 10:19 AM
    Moderator