Unable to create a file using Azure Automation runbook (Powershell)

tamilk 41 Reputation points
2022-06-14T06:15:32.23+00:00

Hi,

I am trying to create a .txt file using PowerShell script in Automation Runbook. The script runs fine if i run it from Windows Powershell but i'm facing in runbook though status is completed. File is not getting created.

Param(

[Parameter (Mandatory=$false)]
[string] $textvaribale
)

$datetimevar = Get-Date-Format "ddMMyyyyhhmmss"

Get-Process | Out-File -FilePath D:\Testing\$datetimevar.txt

$textvaribale | Out-File -FilePath D:\Testing\$datetimevar.txt -Append

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,120 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 17,556 Reputation points
    2022-06-14T09:29:09.607+00:00

    @tamilk Thanks for reaching out. I understand that you are trying to list all of your processes in a text file. When you execute the PowerShell script in your local environment, it uses the local disk to store your file. However, for runbooks, if you need to create temporary files as part of your runbook logic, you can use the Temp folder (that is, $env:TEMP) in the Azure sandbox for runbooks running in Azure. The only limitation is you cannot use more than 1 GB of disk space, which is the quota for each sandbox.

    With the hybrid sandbox, you can use C:\temp based on the availability of storage on a Hybrid Runbook Worker. However, per Azure VM recommendations, you should not use the temporary disk on Windows or Linux for data that needs to be persisted.

    0 comments No comments

  2. Limitless Technology 39,361 Reputation points
    2022-06-15T07:46:23.023+00:00

    Hello Tamil,

    Thanks for posting the query here and we are happy to help you.

    You first need to create a temp file/location since the text file has to be mapped to a physical location.

    If you need to create temporary files as part of your runbook logic, you can use the Temp folder (that is, $env:TEMP) in the Azure sandbox for runbooks running in Azure. The only limitation is you cannot use more than 1 GB of disk space, which is the quota for each sandbox.

    Please refer following links for clear understanding.

    https://learn.microsoft.com/en-us/azure/automation/automation-runbook-execution#temporary-storage-in-a-sandbox

    https://learn.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual

    Following scripts works fine in local as you have mentioned.
    [CmdletBinding(SupportsShouldProcess=$True)]

    Param(

    [Parameter (Mandatory=$false)]
    [string] $textvaribale
    )

    Begin{

    $datetimevar = (get-date).ToString("ddMMyyyyhhmmss")

    Get-Process | Out-File -FilePath C:\Testing\$datetimevar.txt

    $textvaribale | Out-File -FilePath C:\Testing\$datetimevar.txt -Append
    }
    Process{
    }
    End{
    }

    Here is a helpful page with information about Windows PowerShell

    https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/powershell


    --If the reply is helpful, please Upvote and Accept as answer.--

    0 comments No comments