Get-AllServiceEndpointSubnets.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<#
 .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