简体   繁体   中英

Azure: Store the result of powershell into storage account

I'm trying to write simple script to save the output of first command in CSV format into azure storage account, this is part from automation process.

Search-AzureRmGraph -Query "project name, type, location | order by name asc"-0| Export-Csv AutomationFile.csv 

Set-AzureStorageBlobContent -Container resourcegraphcontainer -File AutomationFile.csv -Blob SavedFile.csv

The issue that I'm receiving the following error, I checked and I can extract the file to my local machine but the idea of saving the output into storage account does not work

Try the command as below, it works fine on my side, I use the Get-AzureRmVM to test, just replace it with what you need.

Get-AzureRmVM -ResourceGroupName joywebapp -status | Export-Csv "$Env:temp/AutomationFile.csv"
$Context = New-AzureStorageContext -StorageAccountName "<StorageAccountName>" -StorageAccountKey "<StorageAccountKey>"
Set-AzureStorageBlobContent -Context $Context -Container "111" -File "$Env:temp/AutomationFile.csv" -Blob "SavedFile.csv"

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM