Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perhaps also collect Network IP Settings while collecting CDP Info? #33

Open
TrevorW7 opened this issue Feb 7, 2024 · 0 comments
Open

Comments

@TrevorW7
Copy link

TrevorW7 commented Feb 7, 2024

Most people I know would simultaneously want the IP Settings for the network adapters along with the CDP/LLDP info. For example, when adapters are in a team, the CDP/LLDP info relates to the adapters that are members of each respective team, but the Team adapters don't actually connect to any devices. The IP settings are either on a standard network adapter (no teaming), or the IP settings are set/applied on the Team adapters. CDP info should NOT be collected for a Team adapter (doesn't directly connect to anything).
IMHO: IP Settings should be collected at the same time, but in a different array.

In addition, if there are many servers to remotely access, it would be more proficient to use the same remote session to collect adapter IP settings. More reasoning to add this capability - get both at once.

The code below provides an example of what I am suggesting and collects the network adapter IP info needed. If it were to be added to your code, I would suggest outputting results in two arrays contained on one parent object:

CDPAdapters (adapters physically connected to devices - what is collected now), and
NetworkAdapters (IP settings of adapters - standard and Team adapters)

Example code to collect IP Info:

$teams = get-netlbfoteam
    $hostname = Hostname
    [array]$teamsInfo = @()
    foreach ($team in $teams) {      
        $name = $team.name
        $mode = $team.TeamingMode.ToString()
        $members = $team.members -join "`n"
        $nics = $team.TeamNics
        $vlanID = ($team | get-netlbfoteamnic).VlanID
        if ($null -eq $vlanID) { $vlanID = "No tag specified" }

        $obj = [pscustomobject]@{
            "Hostname"       = $hostname
            "TeamName"       = $name
            "TeamingMode"    = $mode
            "Members"        = $members
            "VirtualNicName" = $nics
            "VlanID"         = $vlanID
        }    
        $teamsInfo += $obj
    }
    $networkInfo = @()
    $networks = Get-NetAdapter 
    foreach ($network in $networks) {
        $ipInfo = Get-CIMInstance -Classname Win32_NetworkAdapterConfiguration | ? {$_.SettingId -eq $network.InterfaceGuid}

        if($ipInfo.IpAddress) {$IPAddress = $ipInfo.IpAddress[0]} else {$IPAddress = "Not Assigned"}
        if($ipInfo.IPSubnet) {$SubnetMask = $ipInfo.IPSubnet[0]} else {$SubnetMask = "Not Assigned"}
        $WINS1 = $ipInfo.WINSPrimaryServer
        $WINS2 = $ipInfo.WINSSecondaryServer   
        if ($null -ne $WINS1 -and $null -ne $WINS2) {$WINS = @($WINS1,$WINS2)} elseif($null -ne $WINS1) {$WINS = $WINS1} elseif($null -ne $WINS2){$WINS = $WINS2} else {$WINS = ""}             
        $IsDHCPEnabled = $false
        If($ipInfo.DHCPEnabled) {
            $IsDHCPEnabled = $true
        }

        if($teamsInfo -and $teamsInfo.Count -gt 0) {
            $matchingTeam = $teamsInfo | Where-Object {$_.VirtualNicName -eq $network.Name}

            if($matchingTeam) {
                $teamName     = $matchingTeam.TeamName
                $teamingMode  = $matchingTeam.TeamingMode
                $members      = $matchingTeam.Members
                $vlanID       = $matchingTeam.VlanID
            } else {
                $teamName     = "Not in a Team"
                $teamingMode  = "None"
                $members      = $null
                $vlanID       = $null
            }

        } else {
            $teamName     = "Not in a Team"
            $teamingMode  = "None"
            $members      = $null
            $vlanID       = $null
        }

        $ipV4enabled = (Get-NetAdapterBinding -Name $network.Name -ComponentID ms_tcpip).Enabled
        $ipV6enabled = (Get-NetAdapterBinding -Name $network.Name -ComponentID ms_tcpip6).Enabled

        $obj  = New-Object -Type PSObject
        $obj | Add-Member -MemberType NoteProperty -Name Hostname -Value $hostname
        $obj | Add-Member -MemberType NoteProperty -Name Name -Value $network.Name
        $obj | Add-Member -MemberType NoteProperty -Name SystemName -Value $network.SystemName
        $obj | Add-Member -MemberType NoteProperty -Name Description -Value $network.ifDesc
        $obj | Add-Member -MemberType NoteProperty -Name TeamName -Value $teamName
        $obj | Add-Member -MemberType NoteProperty -Name TeamingMode -Value  $teamingMode
        $obj | Add-Member -MemberType NoteProperty -Name Members -Value $members
        $obj | Add-Member -MemberType NoteProperty -Name Virtual -Value $network.Virtual
        $obj | Add-Member -MemberType NoteProperty -Name TeamVlanID -Value $vlanID
        $obj | Add-Member -MemberType NoteProperty -Name VlanID -Value $network.VlanID  
        $obj | Add-Member -MemberType NoteProperty -Name IPEnabled -Value $ipInfo.IPEnabled
        $obj | Add-Member -MemberType NoteProperty -Name IpV4enabled -Value $ipV4enabled
        $obj | Add-Member -MemberType NoteProperty -Name IpV6enabled -Value $ipV6enabled
        $obj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
        $obj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask
        $obj | Add-Member -MemberType NoteProperty -Name Gateway -Value ($ipInfo.DefaultIPGateway -join ",") 
        $obj | Add-Member -MemberType NoteProperty -Name DNSDomainSuffixSearchOrder -Value ($ipInfo.DNSDomainSuffixSearchOrder -join ",")
        $obj | Add-Member -MemberType NoteProperty -Name DHCPEnabled -Value $IsDHCPEnabled
        $obj | Add-Member -MemberType NoteProperty -Name DHCPLeaseExpires -Value $ipInfo.DHCPLeaseExpires
        $obj | Add-Member -MemberType NoteProperty -Name DNSServers -Value ($ipInfo.DNSServerSearchOrder -join ",")     
        $obj | Add-Member -MemberType NoteProperty -Name WINSServers -Value  $WINS  
        $obj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $network.MACAddress
        $obj | Add-Member -MemberType NoteProperty -Name LinkSpeed -Value $network.LinkSpeed
        $obj | Add-Member -MemberType NoteProperty -Name Status -Value $network.Status
        $obj | Add-Member -MemberType NoteProperty -Name AdminStatus -Value $network.AdminStatus
        $obj | Add-Member -MemberType NoteProperty -Name ifOperStatus -Value $network.ifOperStatus  
        $obj | Add-Member -MemberType NoteProperty -Name MediaType -Value $network.MediaType
        $obj | Add-Member -MemberType NoteProperty -Name DriverVersion -Value $network.DriverVersion
        $obj | Add-Member -MemberType NoteProperty -Name DriverVersionString -Value $network.DriverVersionString
        $obj | Add-Member -MemberType NoteProperty -Name DriverInformation -Value $network.DriverInformation
        $obj | Add-Member -MemberType NoteProperty -Name DriverFileName -Value $network.DriverFileName
        $obj | Add-Member -MemberType NoteProperty -Name DriverName -Value $network.DriverName
        $obj | Add-Member -MemberType NoteProperty -Name DriverDate -Value $network.DriverDate
        $obj | Add-Member -MemberType NoteProperty -Name InterfaceGuid -Value $network.InterfaceGuid
        $obj | Add-Member -MemberType NoteProperty -Name MtuSize -Value $network.MtuSize
        $obj | Add-Member -MemberType NoteProperty -Name ActiveMaximumTransmissionUnit -Value $network.ActiveMaximumTransmissionUnit
        $obj | Add-Member -MemberType NoteProperty -Name iSCSIInterface -Value $network.iSCSIInterface

      $networkInfo += $obj
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant