Get-AllServiceEndpointSubnets.psm1

<#
 .Synopsis
  List all the Subnets in a Subscription with ServiceEndpoint enabled.
  
 .Description
  List all the Subnets in a Subscription with ServiceEndpoint enabled.
  
 .Parameter none
  No parameters
  
 .Example
   # List all the Subnets in a Subscription with ServiceEndpoint enabled.
   Get-AllServiceEndpointSubnets
     
     
#>


#------------------------------------------------------------------------------
#
#
# THIS CODE AND ANY ASSOCIATED INFORMATION ARE PROVIDED “AS IS” WITHOUT
# WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR
# RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#
#------------------------------------------------------------------------------

function Get-AllServiceEndpointSubnets {
param()

#Get VNETs
$vnet = Get-AzVirtualNetwork

#Get VNETS with ServiceEndpoint
$serviceEPVnets = $vnet | Where-Object {$_.Subnets.ServiceEndpoints -ne $null}

$getSEPSubs  = @()
for ($i =0; $i -lt $serviceEPVnets.Count; $i++){
$getSEPSubs += Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $serviceEPVnets[$i]
}

#Get Subnets with ServiceEndpoint
$getSEPSubsall = $getSEPSubs | Where-Object {$_.ServiceEndpoints -ne $null}
#$getSEPSubsall
#$getSEPSubsall will list the Subnets with ServiceEndpoints


$SEPSubDetails = New-Object -TypeName PSObject

for ($i= 0; $i -lt $getSEPSubsall.count; $i++){
$SEPSubDetails | Add-Member -Name SubnetName$i -MemberType Noteproperty -Value $($getSEPSubsall.name[$i]) 
$SEPSubDetails | Add-Member -Name SubnetID$i -MemberType Noteproperty -Value $($getSEPSubsall.id[$i])
$SEPSubDetails | Add-Member -Name ServiceEndpoint$i -MemberType Noteproperty -Value $(($getSEPSubsall[$i].ServiceEndpoints) | Out-String)
}

$SEPSubDetails

}

Export-ModuleMember -Function Get-AllServiceEndpointSubnets