0

I'm using the below script:

Powershell script to get only specific Fields in an azure webapp But that appears not to complete the requirement.

1 Answer 1

0

Below is the script that worked for me.

$PrivateEndPoints = Get-AzPrivateEndpoint
$Result=@()
For($I=0;$I -lt $PrivateEndPoints.count;$I++) {
    $PrivateLinkServiceId = $PrivateEndPoints[$I].PrivateLinkServiceConnections.PrivateLinkServiceId
    $SubnetId = $PrivateEndPoints[$I].Subnet.Id
    $WebAppArray = $PrivateEndPoints[$I].PrivateLinkServiceConnections.PrivateLinkServiceId.ToLower() -split "/"
    $SubnetArray = $SubnetId -split "/"
    if(($WebAppArray -like "*Microsoft.Web*") -and ($SubnetId -like "*virtualNetworks*"))
    {           
        For($J=0;$J -lt $SubnetArray.count;$J++){           
            $SubnetNameIndex = $SubnetArray.indexOf("subnets") + 1
            $SubnetName = $SubnetArray[$SubnetNameIndex]
        }
        For($J=0;$J -lt $SubnetArray.count;$J++){           
            $VnetNameIndex = $SubnetArray.indexOf("virtualNetworks") + 1
            $VnetName = $SubnetArray[$VnetNameIndex]
        }
        For($J=0;$J -lt $WebAppArray.count;$J++){           
            $WebAppNameIndex = $WebAppArray.indexOf("sites") + 1
            $WebAppName = $WebAppArray[$WebAppNameIndex]
        }
        $obj = [PSCustomObject]@{
            WebAppName = $WebAppName
            PrivateEndpointName = $PrivateEndPoints[$I].Name
            VnetName = $VnetName
            Subnets = $SubnetName
        }
        $Result+=$obj
    }
}
$Result

RESULTS: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.