Search code examples
azurepowershellazure-web-app-serviceazure-powershell

Unable to fetch values using azure powershell code


I'm trying to fetch the username and password from the publishing profile of the azure web app with the Azure PowerShell code, but i'm getting the error in username fetching line.

$WebApp = Get-AzWebApp -ResourceGroupName "Practice-RG" -Name "testwebapp7298"
$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp
# Create Base64 authorization header

$username = $publishingProfile.publishData.publishProfile[0].userName
# OUTPUT: InvalidOperation: Cannot index into a null array.

$password = $publishingProfile.publishData.publishProfile[0].userPWD
# OUTPUT: InvalidOperation: Cannot index into a null array.

$publishingProfile.publishData.publishProfile[0].userName           
# OUTPUT: InvalidOperation: Cannot index into a null array.

Could anyone help me where the syntax gone wrong?

Note: I need this solution in only PowerShell not in Azure CLI or other.


Solution

  • Note: I need this solution in only PowerShell not in Azure CLI or other.

    You can use below commands to get desired result:

    $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