Skip to content

Get-ComputerInfo

Windows: Retrieves consolidated system and operating system information

#Requires -Version 5.1

[CmdletBinding()]
Param
(
    [string]$ComputerName = $env:COMPUTERNAME,

    [pscredential]$Credential,

    [string[]]$Property = @(
        'CsName',
        'OsName',
        'OsVersion',
        'OsArchitecture',
        'BiosSeralNumber',
        'CsManufacturer',
        'CsModel',
        'OsInstallDate',
        'OsLastBootUpTime'
    )
)

Process
{
    try
    {
        $infoParams = @{
            'Property'    = $Property
            'ErrorAction' = 'Stop'
        }

        if ($ComputerName -ne $env:COMPUTERNAME)
        {
            $sessionParams = @{
                'ComputerName' = $ComputerName
            }
            if ($null -ne $Credential)
            {
                $sessionParams.Add('Credential', $Credential)
            }

            $result = Invoke-Command @sessionParams -ScriptBlock {
                Param($Prop)
                Get-ComputerInfo -Property $Prop
            } -ArgumentList $Property
        }
        else
        {
            $result = Get-ComputerInfo @infoParams
        }

        Write-Output $result
    }
    catch
    {
        throw
    }
}

Specifies the name of the computer to query. Defaults to the local computer.

Specifies a PSCredential object for remote connection.

Specifies the specific properties to retrieve. Supports wildcards. Defaults to essential summary properties.

An interactive directory of PowerShell scripts.