forked from a4099181/vagrant-officeVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpn.psm1
99 lines (76 loc) · 3.55 KB
/
vpn.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Function Connect-Vpn
{
<#
.SYNOPSIS
This function connects VPN.
.DESCRIPTION
This function in details:
* takes a dialup credentials list from configuration file,
* establishes VPN connection,
* supports encrypted secret data,
* uses rasdial tool to establish VPN connection.
.PARAMETER CfgFile
Configuration file.
.PARAMETER KeyFile
Encryption key file. If you don't have it, please see New-EncryptionKey.
.PARAMETER ConnectionName
VPN connection name to connect.
.LINK
https://github.com/a4099181/vagrant-officeVM/blob/master/docs/Connect-Vpn.md
.LINK
https://github.com/a4099181/vagrant-officeVM/blob/master/docs/New-EncryptionKey.md
.LINK
https://github.com/a4099181/vagrant-officeVM/blob/master/docs/Protect-Config.md
.LINK
https://github.com/a4099181/vagrant-officeVM/blob/master/provision/powershell/vpn.psm1
#>
Param ( [Parameter(Mandatory=$true)][String] $CfgFile
, [Parameter(Mandatory=$true)][String] $KeyFile
, [Parameter(Mandatory=$true)][String] $ConnectionName )
$cfg = Get-Content $CfgFile | ConvertFrom-Json
$cfg.vault |
Select-Object -expand secret |
Decrypt $KeyFile
$cfg.vault |
Where-Object { $_.type -eq "dialup" } |
Where-Object { $_.secret.name -eq $ConnectionName } |
ForEach-Object { rasdial `"$($_.secret.name)`" `"$($_.secret.username)`" `"$($_.secret.password)`" /domain:`"$($_.secret.domain)`"; ` }
}
Function Add-VpnConnectionTriggers
{
<#
.SYNOPSIS
This function adds VPN connection triggers.
.DESCRIPTION
This function in details registers VPN application triggers for specified
* executables,
* universal apps.
The primary aim is more ergonomics.
.PARAMETER ConnectionName
VPN connection name.
.PARAMETER ExecutablePaths
Paths where specified executable should be search for.
.PARAMETER Executables
Executable to register as VPN connection triggers.
.PARAMETER UniversalApps
Universal Apps to register as VPN connection triggers.
Please note, that universal app are searched using .EndsWith(<param-value>) function.
.LINK
https://github.com/a4099181/vagrant-officeVM/blob/master/docs/Add-VpnConnectionTriggers.md
.LINK
https://github.com/a4099181/vagrant-officeVM/blob/master/provision/powershell/vpn.psm1
#>
Param ( [Parameter(Mandatory=$true)][String] $ConnectionName
, [String[]] $ExecutablePaths=( ${env:ProgramFiles(x86)}, $env:ProgramW6432 , $env:USERPROFILE, "$env:windir\System32" )
, [String[]] $Executables=( 'devenv.exe', 'eTask.exe', 'mintty.exe', 'mstsc.exe' )
, [String[]] $UniversalApps=( '.MicrosoftEdge' ) )
$current = Get-VpnConnectionTrigger "$connectionName" |
Select-Object -ExpandProperty ApplicationID
Get-ChildItem -Path $ExecutablePaths -Include $Executables -File -Recurse |
Where-Object { !$current -Or -Not $current.Contains($_.FullName) } |
ForEach-Object { Add-VpnConnectionTriggerApplication -ApplicationID "$($_.FullName)" -ConnectionName "$connectionName" }
Get-AppxPackage |
Where-Object {$name=$_.Name}{ @( $UniversalApps | Where-Object { $name.EndsWith($_) } ).Count -gt 0 } |
Where-Object { !$current -Or -Not $current.Contains($_.PackageFamilyName) } |
ForEach-Object { Add-VpnConnectionTriggerApplication -ApplicationID "$($_.PackageFamilyName)" -ConnectionName "$connectionName" }
}