无法使用azure powershell代码获取值

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

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

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

任何人都可以帮我解决语法错误的地方吗?

注意我只需要在 PowerShell 中使用此解决方案,而不是在 Azure CLI 或其他中。

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

注意我只需要在 PowerShell 中使用此解决方案,而不是在 Azure CLI 或其他中。

您可以使用以下命令来获得所需的结果:

$rithapp = Get-AzWebApp -ResourceGroupName "rbojja" -Name "rithwik9"
$rithprofile = Get-AzWebAppPublishingProfile -WebApp $rithapp
$test = [xml]$rithprofile
$username = $test.publishData.publishProfile[0].userName
$password = $test.publishData.publishProfile[0].userPWD

Output:

enter image description here

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