-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test21.ps1
61 lines (43 loc) · 1.58 KB
/
Test21.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
57
58
59
60
61
$modPath = "C:\Users\simatic\source\repos\tia-ps\TiaPsCmdlet\TiaCmdlet\bin\Debug\net462\TiaCmdlet.dll"
Import-Module $modPath
function findNetHost($deviceItem, $hostlist)
{
Write-Debug "[findNetHost] check the $($deviceItem.Name)"
Write-Debug "[findNetHost] $($hostlist.GetType())"
try {
$ift = $deviceItem.GetAttribute("InterfaceType")
if ($ift -ne $null)
{
Write-Debug "[findNetHost] found"
$hostlist = $hostlist + @(,$deviceItem)
}
}
catch
{
Write-Debug "[findNetHost] exception $_"
}
foreach ($di in $deviceItem.Items)
{
$hostlist = findNetHost -deviceItem $di -hostlist $hostlist
}
Write-Debug "[findNetHost] done with the $($deviceItem.Name)"
$hostlist
}
function getNetInterface($deviceItem)
{
$netif = $deviceItem.GetService
}
$DebugPreference = "Continue"
$tp = Get-TiaInstance
$prj = ($tp | Get-TiaProject)
$dev = ($prj | Get-TiaDeviceList -Path "G1" | where-object Name -eq -Value "D1_1")
$dhost = findNetHost $dev.Items @()
$gsm = $dhost.GetType().GetMethod("GetService")
$methodCall = $gsm.MakeGenericMethod([Siemens.Engineering.HW.Features.NetworkInterface])
$netif = $methodCall.Invoke($dhost, $null)
$subnet = $netif.Nodes[0].ConnectedSubnet
$subnet.Nodes | % { $_.GetAttribute("Address") }
$ien = New-Object 'System.Collections.Generic.List``1[System.String]'
$ien.Add("Address")
$ien.Add("SubnetMask")
$subnet.Nodes | % { $x = $_.GetAttributes($ien); [PSCustomObject]@{ Address = $x[0]; SubnetMask = $x[1]} } | ft