# encoding: ascii
# api: powershell
# title: CorpTools Module
# description: CorpTools.psm1
# version: 0.1
# type: function
# author: Don Jones
# license: CC0
# function: Get-CorpNetInfo
# x-poshcode-id: 5255
# x-archived: 2014-06-26T08:02:06
# x-published: 2014-06-20T17:12:00
#
#
function Get-CorpNetInfo {
    [cmdletbinding()]
    param(
        [Parameter(Mandatory,ValueFromPipeline)]
        [string[]]$ComputerName
    )
    PROCESS {
        foreach ($computer in $computername) {
            # open a session
            $session = New-CimSession -ComputerName $computer

            # get the adapters & enumerate them
            $adapters = Get-NetAdapter -CimSession $session -Physical
            foreach ($adapter in $adapters) {

                # get corresponding addresses and enumerate them
                $addresses = Get-NetIPAddress -CimSession $session -InterfaceIndex ($adapter.ifIndex)
                foreach ($address in $addresses) {

                    # construct output using computer, adapter, and address info
                    $output = @{'ComputerName'=$computer;
                                'Adapter'     =$adapter.name;
                                'ifIndex'     =$adapter.ifIndex;
                                'Speed'       =$adapter.LinkSpeed;
                                'IPAddress'   =$address.IPAddress;
                                'Subnet'      =$address.Prefixlength}
                    $obj = New-Object -TypeName PSObject -Property $output
                    $obj.psobject.typenames.insert(0,'Corp.NetInfo')
                    Write-Output $obj

                } #foreach address
            } #foreach adapter

            #close the session
            $session | Remove-CimSession

        } #foreach computer
    }#PROCESS
}#function
