Ermittlung von Uplinkport und Netzwerkverbindung
Microsoft.SystemCenter.VirtualMachineManager.2016.UplinkPort.DiscoveryRule (Discovery)
Ermittlung des Uplinkports für virtuelle Switches und ihrer Verbindung mit Computernetzwerkadaptern.
Element properties: Object Discovery Details: Member Modules:
Source Code: <Discovery ID="Microsoft.SystemCenter.VirtualMachineManager.2016.UplinkPort.DiscoveryRule" Enabled="true" Target="VMMBase!Microsoft.SystemCenter.VirtualMachineManager.Network.VSwitch">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.SystemCenter.VirtualMachineManager.Network.2016.UplinkPort"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>1800</IntervalSeconds>
<SyncTime/>
<ScriptName>PowerShellScript</ScriptName>
<ScriptBody><Script>
$evt = New-Object System.Diagnostics.Eventlog("Application");
$evt.Source = "Microsoft.SystemCenter.VirtualMachineManager.2016.UplinkPort.Discovery";
$infoevent = [System.Diagnostics.EventLogEntryType]::Information;
$errevent = [System.Diagnostics.EventLogEntryType]::Error;
$DeviceIdNotFoundErrorCode = 25975
$DiscoverySuccessCode = 25976
# Create a new discovery data packet
$oAPI = new-object -comObject "MOM.ScriptAPI"
$Discovery = $oAPI.CreateDiscoveryData(0, "$MPElement$", "$Target/Id$")
$HostName = "$Target/Property[Type="VMMBase!Microsoft.SystemCenter.VirtualMachineManager.Network.VSwitch"]/HostName$"
$SwitchName = "$Target/Property[Type="VMMBase!Microsoft.SystemCenter.VirtualMachineManager.Network.VSwitch"]/SwitchName$"
$VMMId = "$Target/Host/Property[Type="VMMBase!Microsoft.SystemCenter.VirtualMachineManager.VMHost"]/VMMId$"
$AdapterId = "$Target/Property[Type="VMMBase!Microsoft.SystemCenter.VirtualMachineManager.Network.VSwitch"]/AdapterId$"
#Query the local physical Nics with the adapter id
$WmiObj = gwmi -Query "Select * from Win32_NetworkAdapter where GUID='$AdapterId'"
if ($WmiObj -ne $null)
{
$DeviceId = $WmiObj.DeviceID
$UplinkDisplayName = "Uplink - " + $SwitchName
$ConnectionDisplayName = "Connection with " + $SwitchName
Write-Verbose "Creating Uplink Port for Switch : $UplinkDisplayName"
$UplinkPortInstance = $Discovery.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.VirtualMachineManager.Network.2016.UplinkPort']$")
$UplinkPortInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $HostName)
$UplinkPortInstance.AddProperty("$MPElement[Name='VMMBase!Microsoft.SystemCenter.VirtualMachineManager.Network.VSwitch']/SwitchName$", $SwitchName)
$UplinkPortInstance.AddProperty("$MPElement[Name='VMMBase!Microsoft.SystemCenter.VirtualMachineManager.VMHost']/VMMId$", $VMMId)
$UplinkPortInstance.AddProperty("$MPElement[Name='VMMBase!Microsoft.SystemCenter.VirtualMachineManager.Network.VirtualNetworkAdapter']/DeviceId$", $DeviceId)
$UplinkPortInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $UplinkDisplayName)
$Discovery.AddInstance($UplinkPortInstance)
$NetworkConnectionInstance = $Discovery.CreateClassInstance("$MPElement[Name='SystemNetLib!System.NetworkManagement.NetworkConnection']$")
$NetworkConnectionInstance.AddProperty("$MPElement[Name='SystemNetLib!System.NetworkManagement.Connection']/Key$", $HostName + "_" + $SwitchName + "_" + $DeviceId)
$NetworkConnectionInstance.AddProperty("$MPElement[Name='SystemNetLib!System.NetworkManagement.Connection']/Description$", $ConnectionDisplayName)
$NetworkConnectionInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $ConnectionDisplayName)
$Discovery.AddInstance($NetworkConnectionInstance)
$NetworkAdapterInstance = $Discovery.CreateClassInstance("$MPElement[Name='Windows!Microsoft.Windows.ComputerNetworkAdapter']$")
$NetworkAdapterInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.ComputerNetworkAdapter']/DeviceID$", $DeviceId)
$NetworkAdapterInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $HostName)
$Discovery.AddInstance($NetworkAdapterInstance)
$NWConnectionContainsUplinkPortRelationship = $Discovery.CreateRelationshipInstance("$MPElement[Name='SystemNetLib!System.NetworkManagement.NetworkConnectionConnectedToNetworkAdapter']$")
$NWConnectionContainsUplinkPortRelationship.Source = $NetworkConnectionInstance
$NWConnectionContainsUplinkPortRelationship.Target = $UplinkPortInstance
$Discovery.AddInstance($NWConnectionContainsUplinkPortRelationship)
$NWConnectionContainsPNICRelationship = $Discovery.CreateRelationshipInstance("$MPElement[Name='SystemNetLib!System.NetworkManagement.NetworkConnectionConnectedToNetworkAdapter']$")
$NWConnectionContainsPNICRelationship.Source = $NetworkConnectionInstance
$NWConnectionContainsPNICRelationship.Target = $NetworkAdapterInstance
$Discovery.AddInstance($NWConnectionContainsPNICRelationship)
}
else
{
$evt.WriteEntry("DeviceId info not found for switch: " + $SwitchName, $infoevent, $DeviceIdNotFoundErrorCode);
}
# Return the discovery data
$Discovery
</Script> </ScriptBody>
<SnapIns/>
<Parameters/>
<TimeoutSeconds>120</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</DataSource>
</Discovery>