-
Notifications
You must be signed in to change notification settings - Fork 2
/
AMLPrivateEndpts-RemoveNetPolicy.ps1
56 lines (40 loc) · 1.89 KB
/
AMLPrivateEndpts-RemoveNetPolicy.ps1
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
<#
Script based on documentation below:
https://docs.microsoft.com/en-us/azure/private-link/disable-private-endpoint-network-policy
Connect to Azure and prompting for subscription to set context to
Prompting and menus to gather the noted variables in document
Show Subnet settings and Set if desired
#>
Connect-AzAccount
$Subs = Get-AzSubscription
Foreach($Sub in $Subs){
Write-Host ($Subs.Indexof($Sub)+1) "-" $Sub.Name
}
$Selection = Read-Host "Subscription"
$Selection = $Subs[$Selection-1]
Select-AzSubscription -SubscriptionObject $Selection | Out-Null
CLS
$VNets = Get-AzVirtualNetwork
Foreach($VNet in $VNets){
Write-Host ($VNets.Indexof($Vnet)+1) "-" $Vnet.Name " : " $VNet.AddressSpace.AddressPrefixes
}
$Selection = Read-Host "Select number corresponding to the VNet"
$VNet = $VNets[$Selection-1]
CLS
$Subnets = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $VNet
Write-Host "0 - Exit"
Foreach($Subnet in $Subnets){
Write-Host ($Subnets.Indexof($Subnet)+1) "-" $Subnet.Name " : " $Subnet.PrivateEndpointNetworkPolicies
}
$Selection = Read-Host "To CHANGE the PrivateEndpointNetworkPolicies select the appropriate subnet or 0 <zero> to EXIT"
If($Selection -eq 0){Break}
$SubnetToChange = $Subnets[$Selection-1]
$SubnetName = $SubnetToChange.Name
Write-Host ""
If($SubnetToChange.PrivateEndpointNetworkPolicies -eq 'Enabled'){$SetPolicyTo = "Disabled"}
If($SubnetToChange.PrivateEndpointNetworkPolicies -eq 'Disabled'){$SetPolicyTo = "Enabled"}
($VNet | Select -ExpandProperty subnets | Where-Object {$_.Name -eq $SubnetName}).PrivateEndpointNetworkPolicies = $SetPolicyTo
Write-Host "Changing" $SubnetName "to" $SetPolicyTo "..." -ForegroundColor Yellow
$VNet | Set-AzVirtualNetwork | Out-Null
$SubnetNow = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $VNet | Where Name -EQ $SubnetName
Write-Host $SubnetNow.Name " : " $SubnetNow.PrivateEndpointNetworkPolicies -ForegroundColor Green