通过powershell从kudu(azure web app)下载文件

a7qyws3x  于 2021-06-21  发布在  Kudu
关注(0)|答案(1)|浏览(449)

我想通过powershell从kudu下载文件,通过invoke-webrequest,我得到的只是一个filename.log,没有日志数据,从日志文件中看到的是azure“登录到你的帐户”的登录屏幕。

网址

“调用webrequest”https://appname.scm.azurewebsites.net/api/vfs/logfiles/filename.log“-outfile$filepath1 get childitem-file$filepath1-recurse | set azurestorageblobcontent-container filescontainer-context$storagecontext”

gc0ot86w

gc0ot86w1#

需要在invoke webrequest for authentication的标头中提供webapp发布配置文件的用户名和密码。
您可以在发布配置文件中获取用户名和密码。您可以从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"

相关问题