InvalidOperation:无法索引到空数组 - 在 Azure PowerShell 中从数组中获取值时

问题描述 投票:0回答:1

我尝试使用 Azure PowerShell 代码从 azure Web 应用程序的发布配置文件中获取用户名和密码,但我在用户名获取行中收到错误”

代码

$WebApp = Get-AzWebApp -ResourceGroupName "Practice-RG" -Name "testwebapp7298"
$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp
# Create Base64 authorization header
$username = $publishingProfile.publishData.publishProfile[0].userName
$password = $publishingProfile.publishData.publishProfile[0].userPWD

结果

PS /home/sheethal> $WebApp = Get-AzWebApp -ResourceGroupName "Practice-RG" -Name "testwebapp7298"
PS /home/sheethal> $publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp
PS /home/sheethal> # Create Base64 authorization header
PS /home/sheethal> $username = $publishingProfile.publishData.publishProfile[0].userName
InvalidOperation: Cannot index into a null array.
PS /home/sheethal> $password = $publishingProfile.publishData.publishProfile[0].userPWD
InvalidOperation: Cannot index into a null array.
PS /home/sheethal> $publishingProfile.publishData.publishProfile[0].userName           
InvalidOperation: Cannot index into a null array.
PS /home/sheethal> 

有人可以纠正我代码中的错误吗?

azure powershell azure-web-app-service azure-powershell azure-appservice
1个回答
0
投票

您可以使用

Get-AzWebAppPublishingProfile
命令编写多行代码,而不是使用
az webapp deployment list-publishing-profiles
轻松从发布配置文件中获取用户名和密码。

$userNames=az webapp deployment list-publishing-profiles --name newjan --resource-group xxxx --query '[].userName' -o tsv
$userNames
$Passwords=az webapp deployment list-publishing-profiles --name newjan --resource-group xxxx --query '[].userPWD' -o tsv
$Passwords 

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.