PwSh.Fw.Computer.psm1


<#
.SYNOPSIS
Statically declare a new computer
 
.DESCRIPTION
Long description
 
.PARAMETER name
Parameter description
 
.PARAMETER Localhost
Parameter description
 
.EXAMPLE
An example
 
.NOTES
General notes
#>


function New-Computer {
    [CmdletBinding()]Param (
        [Parameter(ValueFromPipeLine = $true)][string]$name,
        [switch]$Localhost
    )
    Begin {
        Write-EnterFunction
    }

    Process {
        $obj = [computer]::new($Localhost)
        if ($name) {
            $obj.name = $name
        }
        return $obj
    }

    End {
        # eleave($MyInvocation.MyCommand)
    }
}

<#
.SYNOPSIS
Create a new [computer] object from an existing computer
 
.DESCRIPTION
Long description
 
.PARAMETER name
Parameter description
 
.PARAMETER Localhost
Parameter description
 
.EXAMPLE
An example
 
.NOTES
General notes
#>


function Get-Computer {
    [CmdletBinding()]Param (
    )
    Begin {
        Write-EnterFunction
        $computer = @{}
    }

    Process {
        $computer.name = Get-ComputerName
        $computer.domain = Get-ComputerDomain
        $computer.fqdn = $computer.name + '.' + $computer.domain
        $computer.manufacturer = Get-ComputerManufacturer
        # $computer.eth = Get-ComputerEthernet
        $computer.model = Get-ComputerModel
        $computer.serial = Get-ComputerSerialNumber
        $computer.firmware = Get-ComputerFirmwareType
        $computer.version = Get-ComputerVersion
        $computer.arch = Get-ComputerArch
        $computer.ethByName = @{}

        ForEach ($e in (Get-ComputerEthernet -ListAvailable 'Name')) {
            $computer.ethByName[$e] = @{}
            try {
                $computer.ethByName[$e]["IPv4"] = Get-EthernetObject -AdapterName $e -Family IPv4
            } catch {
                ewarn "On $e (IPv4):"
                ewarn $_
            }
            try {
                $computer.ethByName[$e]["IPv6"] = Get-EthernetObject -AdapterName $e -Family IPv6
            } catch {
                ewarn "On $e (IPv6):"
                ewarn $_
            }
            if ($computer.ethByName[$e]["IPv4"].default -eq $true) {
                $computer.ethByName["default"] = $computer.ethByName[$e]
            }
            if ($computer.ethByName[$e]) {
                $computer.ethByName[$e].ifindex = $computer.ethByIndex.Count
                $computer.ethByIndex += @($computer.ethByName[$e])
            }
        }
        # ForEach ($e in (

        return $computer
        # return [PwShFwComputer]::new($computer)
    }

    End {
        Write-LeaveFunction
    }
}

<#
.SYNOPSIS
Create a new [computer] object from an existing computer
 
.DESCRIPTION
Long description
 
.PARAMETER name
Parameter description
 
.PARAMETER Localhost
Parameter description
 
.EXAMPLE
An example
 
.NOTES
General notes
#>


function Get-ComputerClass {
    [CmdletBinding()]Param (
        [Parameter(ValueFromPipeLine = $true)][string]$name
    )
    Begin {
        Write-EnterFunction
    }

    Process {
        . "$Global:PWSHFW_PATH/classes/disk/diskObject.ps1"
        . "$Global:PWSHFW_PATH/classes/ethernet/ethernetObject.ps1"
        . "$Global:PWSHFW_PATH/classes/computer/computerObject.ps1"

        $obj = [computer]::new($Localhost)
        if ($name) {
            $obj.name = $name
        }
        return $obj
    }

    End {
        # eleave($MyInvocation.MyCommand)
    }
}

function Get-EthernetObject {
    [CmdletBinding()]Param (
        [Parameter(ValueFromPipeLine = $true)]
        [string]$AdapterName,
        [ValidateSet('IPv4', 'IPv6')]
        [string]$Family = 'IPv4'
    )
    Begin {
        Write-EnterFunction
        # $eth = New-Object -TypeName PSObject -Property @{
        # # name of network interface
        # name = "lo"
        # # inner index in array eth
        # index = 0
        # # index of interface in operating system
        # ifIndex = 0
        # manufacturer = ""
        # model = ""
        # description = ""
        # mac = "aa:bb:cc:dd:ee:ff"
        # # link status of ethernet interface
        # # $false is link down
        # # $true is link up
        # link = $false
        # speed = 0
        # dhcpIpAddress = $null
        # ipaddress = [ipaddress]"0.0.0.0"
        # netmask = [ipaddress]"255.255.255.255"
        # broadcast = [ipaddress]"255.255.255.255"
        # gateway = [ipaddress]"0.0.0.0"
        # # the score for this interface to be the default
        # scoreDefault = 0
        # default = $false
        # }
        $eth = @{}
    }

    Process {
        $eth.name = $AdapterName
        $eth.ifindex = Get-EthIndex -AdapterName $AdapterName
        $eth.mac = Get-EthMacAddress -AdapterName $AdapterName
        $eth.link = Get-EthLinkStatus -AdapterName $AdapterName
        if ($eth.link -eq $true) {
            $eth.ipaddress = Get-EthIPAddress -AdapterName $AdapterName -Family:$Family
            $eth.netmask = Get-EthNetmask -AdapterName $AdapterName -Family:$Family
            $eth.broadcast = Get-EthBroadcast -AdapterName $AdapterName -Family:$Family
            $eth.gateway = Get-EthGateway -AdapterName $AdapterName -Family:$Family
        }

        # return $eth
        return [PwShFwEthernet]::new($eth)
    }

    End {
        Write-LeaveFunction
    }
}