Discovers VPN Connections group

Microsoft.Windows.RemoteAccess.MultiTenant.2012.R2.Discover.VpnConnections (Discovery)

Discovers the VPN connections group

Element properties:

TargetMicrosoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.RemoteAccessServer
EnabledTrue
Frequency3600
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
Discovered relationships and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
PSDiscoverVpnConnections DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Source Code:

<Discovery ID="Microsoft.Windows.RemoteAccess.MultiTenant.2012.R2.Discover.VpnConnections" Target="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.RemoteAccessServer" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant">
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant" PropertyID="TenantName"/>
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant" PropertyID="RoutingDomain"/>
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant" PropertyID="RoutingDomainID"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.VPN">
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.VPN" PropertyID="Count"/>
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.VPN" PropertyID="TenantName"/>
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.TenentComponents" PropertyID="ServerName"/>
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.TenentComponents" PropertyID="TenantName"/>
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.TenentComponents" PropertyID="RoutingDomain"/>
<Property TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.TenentComponents" PropertyID="RoutingDomainID"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryRelationship TypeID="Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Tenant.Hosts.VPN"/>
</DiscoveryTypes>
<DataSource ID="PSDiscoverVpnConnections" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>3600</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverVpnConnections.ps1</ScriptName>
<ScriptBody><Script>param($sourceId,$managedEntityId,$computerName)

$EventLog = new-object System.Diagnostics.EventLog('Application')
$EventLog.MachineName = "."
$EventLog.Source = "VpnDiscovery"

$api = new-object -comObject 'MOM.ScriptAPI'
$discoveryData = $api.CreateDiscoveryData(0, $sourceId, $managedEntityId)

try{
$routingDomains = @(Get-RemoteaccessRoutingdomain)
$allVpnConnections = @(Get-RemoteAccessConnectionStatistics)

foreach($TenantRoutingDomain in $routingDomains)
{

$routingDomain = $TenantRoutingDomain.RoutingDomain.ToString()
$routingDomainID = $TenantRoutingDomain.RoutingDomainID.Split("{}")[1].ToString()
$vpnConnections = @($allVpnConnections | where RoutingDomain -eq $routingDomain)

if($vpnConnections.Count -gt 0)
{

#Create the tenant instance. This is just to ensure that there the below objects doesnt get dropped if tenant is already discovered.
#The parameters will be filled when tenant discovery happens next time.
$rd = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant']$")
$rd.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$rd.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $routingDomain.ToString())
$rd.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant']/ServerName$", $computerName)
$rd.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant']/TenantName$", $routingDomain)
$rd.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant']/RoutingDomain$", $routingDomain)
$rd.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant']/RoutingDomainID$", $routingDomainID)
$rd.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.RemoteAccessServer']/ServerName$", $computerName)
$discoveryData.AddInstance($rd)

#Creating VPN group instance for this site
$vpnGroup = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.VPN']$")
$vpnGroup.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$vpnGroup.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "VpnConnections (" + $routingDomain + ")")
$vpnGroup.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.TenentComponents']/ServerName$", $computerName)
$vpnGroup.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.TenentComponents']/TenantName$", $routingDomain)
$vpnGroup.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.TenentComponents']/RoutingDomain$", $routingDomain)
$vpnGroup.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.TenentComponents']/RoutingDomainID$", $routingDomainID)

$vpnGroup.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.Tenant']/TenantName$", $routingDomain )
$vpnGroup.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.RemoteAccessServer']/ServerName$", $computerName)
$vpnGroup.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.VPN']/Count$", $vpnConnections.Count)
$vpnGroup.AddProperty("$MPElement[Name='Microsoft.Windows.RemoteAccess.Multitenant.2012.R2.Class.VPN']/TenantName$", $routingDomain )
$discoveryData.AddInstance($vpnGroup)
}
}
}
catch{
$EventLog.WriteEntry("[VpnDiscovery] Error occured while running VPN Discovery at " + $user)
$EventLog.WriteEntry("[VpnDiscovery] Error Data: " + $_)
}
$discoveryData</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>sourceID</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>managedEntityID</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>computerName</Name>
<Value>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>900</TimeoutSeconds>
</DataSource>
</Discovery>