-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-SCVPNConnectionNetworkRoutes.ps1
56 lines (44 loc) · 1.35 KB
/
Get-SCVPNConnectionNetworkRoutes.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
function Import-ModuleIfNotAlreadyImported {
param ([String]$Name)
$isImported = Get-Module | Where-Object {$_.Name -eq $Name}
if (!$isImported) {
Import-Module $Name
}
}
function Get-SCVPNConnectionNetworkRoutes {
param(
[String]$VMnetworkName,
[String]$VPNConnectionName,
[String]$Protocol="L3"
)
if (!$PSCmdlet.$Protocol) {
Write-Warning "`n`n`n$Protocol variable not defined, using L3 as default value..."
}
$VmNetworkObjectRef = Get-SCVMNetwork -Name $VMnetworkName
$vmNetworkGatewayObjectRef = Get-SCVMNetworkGateway -VMNetwork $VmNetworkObjectRef
$vpnConnection = Get-SCVPNConnection -Name $VPNConnectionName -VMNetworkGateway $vmNetworkGatewayObjectRef | Where-Object {$_.Protocol -eq $Protocol}
if ($vpnConnection.count -gt 1) {
throw "More than 1 connection with $VPNConnectionName name ..."
} else {
Get-SCNetworkRoute -VPNConnection $vpnConnection
}
}
##
# module name
$moduleName = "virtualmachinemanager"
#
#
# VM network name
$VmNetworkName = "<VM network name here>"
#
#
# VPN connection name
$VPNConnectionName = "<VPN connection name>"
#
#
# Connection protocol
$protocol = "L3"
#
##
Import-ModuleIfNotAlreadyImported -Name $moduleName
Get-SCVPNConnectionNetworkRoutes -VMnetworkName $VmNetworkName -VPNConnectionName $VPNConnectionName