通过Powershell从KUDU(Azure Web应用程序)下载文件

通过Powershell从KUDU(Azure Web应用程序)下载文件,azure,download,azure-devops,kudu,azure-webapps,Azure,Download,Azure Devops,Kudu,Azure Webapps,我想通过Powershell从Kudu下载文件,使用Invoke WebRequest,我得到的只是一个没有日志数据的filename.log,从日志文件中看到的是azure“登录到您的帐户”的登录屏幕 统一资源定位地址 调用WebRequest“”-输出文件$FilePath1 Get ChildItem-File$FilePath1-Recurse | Set AzureStorageBlobContent-Container FilesContainer-Context$StorageCo

我想通过Powershell从Kudu下载文件,使用Invoke WebRequest,我得到的只是一个没有日志数据的filename.log,从日志文件中看到的是azure“登录到您的帐户”的登录屏幕

统一资源定位地址 调用WebRequest“”-输出文件$FilePath1
Get ChildItem-File$FilePath1-Recurse | Set AzureStorageBlobContent-Container FilesContainer-Context$StorageContext

需要在Invoke WebRequest的标头中提供Web应用程序发布配置文件的用户名和密码以进行身份验证

您可以在发布配置文件中获取用户名和密码。您可以从Azure Web应用程序下载发布配置文件。并参考publishProfile部分中的userName和userPWD值

# 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"
您还可以通过脚本获取用户名和密码,请参见以下示例:

$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"