Scripts/Get-PCNetworkConfiguration.ps1

Function Get-PCNetworkConfiguration {

    <#
 
    .SYNOPSIS
    Get system's network information/configuration
 
    .DESCRIPTION
    Get system's network information/configuration
 
    .PARAMETER ComputerName
    The target computer name
 
    .EXAMPLE
    Get-PCNetworkConfiguration -ComputerName LabPC2024
 
    .NOTES
    N/A
 
    .LINK
    N/A
 
    #>


    [CmdletBinding ()]

    Param (

        [Parameter (Mandatory = $True,
                    ValueFromPipeline = $True,
                    ValueFromPipelineByPropertyName = $True,
                    HelpMessage = 'Enter computer name'
                   )
        ]

        [String[]]$ComputerName

    )

    BEGIN {

        $TCPNetbiosOptions = @{

            '0' = 'Enable Netbios via DHCP'
            '1' = 'Enable Netbios'
            '2' = 'DisableNetbios'

        }

        Function Show-Error ($Computer, $Status) {

            [PSCustomObject]@{

                ComputerName = $Computer
                Description = ''
                IPv4Address = ''
                IPv6Address = ''
                MACAddress = ''
                ServiceName = ''
                IPEnabled = ''
                TCPIPNetbiosOptions = ''
                DHCPEnabled = ''
                DHCPLeaseObtained = ''
                DHCPLeaseExpires = ''
                DHCPServer = ''
                DNSDomain = ''
                DNSDomainSuffixSearchOrder = ''
                DNSEnabledForWINSResolution = ''
                DNSHostName = ''
                DNSServerSearchOrder = ''
                DomainDNSRegistrationEnabled = ''
                FullDNSRegistrationEnabled = ''
                IPConnectionMetric = ''
                IPFilterSecurityEnabled = ''
                WINSEnableLMHostsLookup = ''
                WINSHostLookupFile = ''
                WINSPrimaryServer = ''
                WINSSecondaryServer = ''
                WINSScopeID = ''
                DefaultIPGateway = ''
                DefaultTOS = ''
                DefaultTTL = ''
                ForwardBufferMemory = ''
                GatewayCostMetric = ''
                IGMPLevel = ''
                InterfaceIndex = ''
                IPPortSecurityEnabled = ''
                IPSubnet = ''
                NumForwardPackets = ''
                PMTUBHDetectEnabled = ''
                PMTUDiscoveryEnabled = ''
                TcpMaxConnectRetransmissions = ''
                TcpMaxDataRetransmissions = ''
                TcpUseRFC1122UrgentPointer = ''
                TcpWindowSize = ''
                Status = $Status

            }

        }

    }

    PROCESS {

        ForEach ($Computer In $ComputerName) {

            If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {

                Try {

                    $Data = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | Select-Object *

                    ForEach ($Item In $Data) {

                        $OutputObj = New-Object -TypeName PSObject

                        $IPv4 = ''
                        $IPv6 = ''
                        $IPSubnet = ''
                        [Object]$LeaseObtained = $Null
                        [Object]$LeaseExpires = $Null

                        If ($Item.DHCPLeaseObtained -or $Item.DHCPLeaseExpires) {

                            $LeaseObtained = [System.Management.ManagementDateTimeConverter]::ToDateTime($Item.DHCPLeaseObtained).ToUniversalTime()
                            $LeaseExpires = [System.Management.ManagementDateTimeConverter]::ToDateTime($Item.DHCPLeaseExpires).ToUniversalTime()

                        }

                        If ($Item.IPAddress) {

                            $IPv4 = $Item.IPAddress[0]
                            $IPv6 = $Item.IPAddress[1]
                            $IPSubnet = $Item.IPSubnet[0]

                        }

                        $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper() -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name Description -Value $Item.Description -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name IPv4Address -Value $IPv4 -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name IPv6Address -Value $IPv6 -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $Item.MACAddress -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name ServiceName -Value $Item.ServiceName -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name IPEnabled -Value $Item.IPEnabled -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name TCPIPNetbiosOptions -Value $TCPNetbiosOptions["$($Item.TCPIPNetbiosOptions)"] -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name DHCPEnabled -Value $Item.DHCPEnabled -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name DHCPLeaseObtained -Value $LeaseObtained -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name DHCPLeaseExpires -Value $LeaseExpires -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name DHCPServer -Value $Item.DHCPServer -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name DNSDomain -Value $Item.DNSDomain -Force

                        $Index = 1

                        ForEach ($Element In $Item.DNSDomainSuffixSearchOrder) {

                            $OutputObj | Add-Member -MemberType NoteProperty -Name "$('DNSDomainSuffixSearchOrder_')$($Index)" -Value $Element
                            $Index++

                        }

                        $OutputObj | Add-Member -MemberType NoteProperty -Name DNSEnabledForWINSResolution -Value $Item.DNSEnabledForWINSResolution -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name DNSHostName -Value $Item.DNSHostName -Force

                        $Index = 1

                        ForEach ($Element In $Item.DNSServerSearchOrder) {

                            $OutputObj | Add-Member -MemberType NoteProperty -Name "$('DNSServerSearchOrder_')$($Index)" -Value $Element
                            $Index++

                        }

                        $OutputObj | Add-Member -MemberType NoteProperty -Name DomainDNSRegistrationEnabled -Value $Item.DomainDNSRegistrationEnabled -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name FullDNSRegistrationEnabled -Value $Item.FullDNSRegistrationEnabled -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name IPConnectionMetric -Value $Item.IPConnectionMetric -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name IPFilterSecurityEnabled -Value $Item.IPFilterSecurityEnabled -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name WINSEnableLMHostsLookup -Value $Item.WINSEnableLMHostsLookup -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name WINSHostLookupFile -Value $Item.WINSHostLookupFile -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name WINSPrimaryServer -Value $Item.WINSPrimaryServer -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name WINSSecondaryServer -Value $Item.WINSSecondaryServer -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name WINSScopeID -Value $Item.WINSScopeID -Force

                        $Index = 1

                        ForEach ($Element In $Item.DefaultIPGateway) {

                            $OutputObj | Add-Member -MemberType NoteProperty -Name "$('DefaultIPGateway_')$($Index)" -Value $Element
                            $Index++

                        }

                        $OutputObj | Add-Member -MemberType NoteProperty -Name DefaultTOS -Value $Item.DefaultTOS -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name DefaultTTL -Value $Item.DefaultTTL -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name ForwardBufferMemory -Value $Item.ForwardBufferMemory -Force

                        $Index = 1

                        ForEach ($Element In $Item.GatewayCostMetric) {

                            $OutputObj | Add-Member -MemberType NoteProperty -Name "$('GatewayCostMetric_')$($Index)" -Value $Element
                            $Index++

                        }

                        $OutputObj | Add-Member -MemberType NoteProperty -Name IGMPLevel -Value $Item.IGMPLevel -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name InterfaceIndex -Value $Item.InterfaceIndex -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name IPPortSecurityEnabled -Value $Item.IPPortSecurityEnabled -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name IPSubnet -Value $IPSubnet -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name NumForwardPackets -Value $Item.NumForwardPackets -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name PMTUBHDetectEnabled -Value $Item.PMTUBHDetectEnabled -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name PMTUDiscoveryEnabled -Value $Item.PMTUDiscoveryEnabled -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name TcpMaxConnectRetransmissions -Value $Item.TcpMaxConnectRetransmissions -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name TcpMaxDataRetransmissions -Value $Item.TcpMaxDataRetransmissions -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name TcpNumConnections -Value $Item.TcpNumConnections -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name TcpUseRFC1122UrgentPointer -Value $Item.TcpUseRFC1122UrgentPointer -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name TcpWindowSize -Value $Item.TcpWindowSize -Force
                        $OutputObj | Add-Member -MemberType NoteProperty -Name Status -Value 'Ok' -Force

                        Write-Output $OutputObj

                    }

                }

                Catch {

                    Show-Error $Computer.ToUpper() $PSItem.Exception.Message

                }

            }

            Else {

                Show-Error $Computer.ToUpper() 'Unreachable'

            }

        }

    }

    END {}

}