forked from imabdk/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest-DomainVPNConnectivity.ps1
39 lines (32 loc) · 1.6 KB
/
Test-DomainVPNConnectivity.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
function Test-DomainVPNConnectivity {
$computerName = $env:computername
$domainName = $env:userDNSDomain
if ($domainName) {
Write-Verbose -Verbose -Message "Device: $computerName is domain joined to: $domainName"
$domainConnection = Get-NetConnectionProfile | Where-Object {$_.Name -eq $domainName}
if ($domainConnection) {
Write-Verbose -Verbose -Message "$computerName has an active connection to domain: $domainName"
$interfaceAlias = $domainConnection.InterfaceAlias
$domainConnectionName = $domainConnection.Name
$domainConnectionCategory = $DomainConnection.NetworkCategory
if (($domainConnectionName -eq $domainName) -AND ($domainConnectionCategory -eq "DomainAuthenticated")) {
if (($interfaceAlias -like "Wi-Fi*") -OR ($interfaceAlias -like "Ethernet*")) {
Write-Verbose -Verbose -Message "$computerName is connected to $domainName via local network"
Write-Output "LAN"
}
elseif ($interfaceAlias -like "*VPN*") {
Write-Verbose -Verbose -Message "$computerName is connected to $domainName via VPN"
Write-Output "VPN"
}
}
}
else {
Write-Verbose -Verbose -Message "$computerName does not have an active connection to domain: $domainName"
Write-Output "NODOMAIN"
}
}
else {
Write-Verbose -Verbose -Message "Looks like that $computerName is not domain joined"
Write-Output "NOTDOMAINJOINED"
}
}