CHPCInventory.psm1

$script:ModuleRoot = $PSScriptRoot

function Get-CHPComputerInfo {
    <#
    .SYNOPSIS
    Retrieves computer system and operating system information from local or remote computers.
 
    .DESCRIPTION
    The Get-CHPComputerInfo function retrieves detailed information about computer hardware and operating system
    from one or more computers using WMI/CIM instances. Returns manufacturer, model, OS version, and last boot time.
 
    .PARAMETER ComputerName
    Specifies the names of computers from which to retrieve information. Accepts an array of computer names.
    Defaults to the local computer if not specified.
 
    .EXAMPLE
    Get-CHPComputerInfo -ComputerName "Server01"
 
    Retrieves information for Server01.
 
    .EXAMPLE
    Get-CHPComputerInfo -ComputerName "Server01", "Server02", "Server03"
 
    Retrieves information for multiple computers.
 
    .OUTPUTS
    PSCustomObject
    Returns a custom object with the following properties:
    - ComputerName: The name of the computer
    - Manufacturer: The system manufacturer
    - Model: The system model
    - OSVersion: The operating system version
    - LastBootUpTime: The last time the computer was started
 
    .NOTES
    Requires appropriate permissions to access WMI/CIM instances on target computers.
    #>


    [CmdletBinding()]
    param (
        [Parameter()]
        [PSFComputer[]]
        $ComputerName = $env:COMPUTERNAME
    )

    foreach ($computer in $ComputerName) {
        try {
            $param = @{}
            if (-not $computer.IsLocalhost) { $param.ComputerName = $computer }
            $info = Get-CimInstance -ClassName Win32_ComputerSystem @param -ErrorAction Stop
            $os = Get-CimInstance -ClassName Win32_OperatingSystem @param -ErrorAction Stop

            [PSCustomObject]@{
                PSTypeName     = 'CHPCInventory.CHComputerInfo'
                ComputerName   = $computer
                Manufacturer   = $info.Manufacturer
                Model          = $info.Model
                OSVersion      = $os.Version
                LastBootUpTime = $os.LastBootUpTime
            }
        } catch {
            Write-PSFMessage -Level Warning -Message 'Failed to retrieve information for {0}' -StringValues $computer -ErrorRecord $_ -Target $computer
            Write-Error $_
        }
    }
}


# Commands run on module import go here
# E.g. Argument Completers could be placed here

# Module-wide variables go here
# For example if you want to cache some data, have some module-wide config settings, etc. ... those could go here
# Example:
# $script:config = @{ }

Export-ModuleMember -Function 'Get-CHPComputerInfo'