I want to download files from Kudu via Powershell, with the Invoke-WebRequest all i get is a filename.log without the log data, from what i see in the logfile it's the login screen off azure "Sign in to your account".
Invoke-WebRequest "https://AppName.scm.azurewebsites.net/api/vfs/LogFiles/FileName.Log" -OutFile $FilePath1 Get-ChildItem -File $FilePath1 -Recurse | Set-AzureStorageBlobContent -Container FilesContainer -Context $StorageContext
The User Name and Password of your webapp's Publish Profile need to be provided in the Headers of Invoke-WebRequest for authentication.
You can get the username and password in the Publish Profile. You can download the publish profile from the Azure Web App. And refer userName and userPWD values in the publishProfile section.
# User name from WebDeploy Publish Profile. Use backtick while assigning variable content
$userName = "{userName}"
# Password from WebDeploy Publish Profile
$password = "{Password}"
# Encode username and password to base64 string
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $password)))
# pass the authentication to Header
Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET -OutFile $filePath -ContentType "multipart/form-data"
You can also get the username and password via scripts, see below example:
$ResGroupName = ""
$WebAppName = ""
$LogFolder = ""
# Get publishing profile for web application
$WebApp = Get-AzWebApp -Name $WebAppName -ResourceGroupName $ResGroupName
[xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp
# Create Base64 authorization header
$username = $publishingProfile.publishData.publishProfile[0].userName
$password = $publishingProfile.publishData.publishProfile[0].userPWD
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
# pass the authentication to Header
Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET -OutFile $filePath -ContentType "multipart/form-data"