Azure Automation enables PowerShell (and more) to be executed as runbooks by runbook workers hosted in Azure. Additionally Azure Automation accounts bring capabilities such as credential objects to securely store credentials, variables, scheduling and more. When a runbook executes it runs in a temporary environment that does not have any persistent state and so if you want to work with files you need to save them somewhere, for example to an Azure storage account as a blob, before the runbook completes.
You can actually create and use files as normal using the default path within PowerShell during execution, just remember to save the files externally before the script completes.
For example create a file as usual:
$todaydate = Get-Date -Format MM-dd-yy $LogFull = "AzureScan-$todaydate.log" $LogItem = New-Item -ItemType File -Name $LogFull " Text to write" | Out-File -FilePath $LogFull -Append
Then before ending the PowerShell, copy it to a blob (as an example storage place):
#Get key to storage account $acctKey = (Get-AzureRmStorageAccountKey -Name onemtceastusfs -ResourceGroupName EastUS-Infra-RG).Value #Map to the reports BLOB context $storageContext = New-AzureStorageContext -StorageAccountName "onemtceastusfs" -StorageAccountKey $acctKey #Copy the file to the storage account Set-AzureStorageBlobContent -File $LogFull -Container "azurescan" -BlobType "Block" -Context $storageContext -Verbose