Invoke-RestMethod InFile from Blob Storage

Kode Source

I need to upload a file to a REST endpoint but my file resides in Blob Storage. My end goal is to run this from Azure Automation so I can have a consistent Runbook to add files to new Azure Web Apps.

The challenge I am running into is that InFile appears to look for local storage. I tried using New-PSDrive from Azure Automation (along with New-PSSession), but it won't add my local drive as a session resource within Azure Automation.

Is there anyway to upload to the Rest Endpoint from Blob Storage? I am trying to hit the Kudu Zip Upload API: https://github.com/projectkudu/kudu/wiki/REST-API. I am guessing that some sort of filestream from the Azure Blob to the Azure Web App FTP may be a better way forward.

$username = "`$mywebappusername"
$password = "abcdefghijklmnopqrstuvwxyz"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$userAgent = "powershell/1.0"

$apiUrl = "https://mywebapp.scm.azurewebsites.net/api/zip/site/wwwroot"
$filePath = "https://myblob.blob.core.windows.net/configs/testconfig.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType "multipart/form-data"
powershellazureazure-automation

Answers

comments powered by Disqus