-
Notifications
You must be signed in to change notification settings - Fork 0
/
Remove-VmNetworkGatewayConnection.ps1
70 lines (56 loc) · 1.62 KB
/
Remove-VmNetworkGatewayConnection.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
###
##
# Script to remove SCVMM L3 Forwarding connection for a specific VM network
##
###
##
# Edit $connectionType and $vmNetworkName values and run the script
##
###
function Import-ModuleIfNotAlreadyImported {
param ([String]$Name)
$isImported = Get-Module | Where-Object {$_.Name -eq $Name}
if (!$isImported) {
Import-Module $Name
}
}
function Remove-VmNetworkGatewayConnection {
param (
[String]$VmNetworkName,
[String]$ConnectionType="L3",
[String]$VPNconnectionName
)
$Name = "virtualmachinemanager"
Import-ModuleIfNotAlreadyImported -Name $Name
$vmNetwork = Get-SCVMNetwork -Name $vmNetworkName
$vmNetworkGateway = Get-SCVMNetworkGateway -VMNetwork $vmNetwork
$VPNConnectionObjectRef = Get-SCVPNConnection -VMNetworkGateway $VmNetworkGateway | Where-Object {$_.Protocol -eq $connectionType -and $_.Name -eq $VPNconnectionName}
if ($VPNConnectionObjectRef) {
Remove-SCVPNConnection -VPNConnection $VPNConnectionObjectRef
} else {
throw "$VPNconnectionName connection doesn't exist..."
}
}
# module name
#
#
$moduleName = "virtualmachinemanager"
#
#
# change $vmNetworkName value to the name of VM network;
$vmNetworkName = "Tenant-A-VM-Network"
#
#
# change $connectionType value to type of connection that you want to query;
# valid values are: IKEv2, L2TP, PPTP, GRE, L3, IPSec
#
$connectionType = "L3"
##
#
#
## name of the connection
$VPNConnectionName = "L3F-Tenant-A"
##
#
#
Remove-VmNetworkGatewayConnection -VmNetworkName $vmNetworkName -connectionType $connectionType -VPNconnectionName $VPNConnectionName