Dictionaries/Computer.Dict.OS/Computer.Dict.OS.psm1
|
<#
.SYNOPSIS Get the computer name .DESCRIPTION Return computername without domainname if any .EXAMPLE $name = Get-ComputerName .NOTES This function comes from Dict.Windows module. #> function Get-ComputerName { [CmdletBinding()]Param ( ) Begin { Write-EnterFunction } Process { return (hostname) -replace "\..*" } End { Write-LeaveFunction } } <# .SYNOPSIS Statically create a new TPM object .DESCRIPTION Think of this function as if it were the constructor of the Tpm object. It returns a TPM object with all properties set to their default values (present = $false). The Computer.Dict.<OS> dictionaries fill it in. .EXAMPLE $myTpm = New-ComputerTpmObject .NOTES General notes #> function New-ComputerTpmObject { [CmdletBinding()]Param ( ) Begin { Write-EnterFunction } Process { $tpm = [PSCustomObject]@{ # is a TPM chip detected on this computer present = $false # TPM specification version, e.g. "1.2" or "2.0" version = "" # chip firmware version (vendor specific) firmwareVersion = "" # chip vendor, e.g. Intel, AMD, Nuvoton vendor = "" # raw vendor information string manufacturerInfo = "" # is the TPM initialized and reachable ($null when unknown) ready = $null # is the TPM enabled at boot ($null when not applicable) enabledOnBoot = $null # device path, e.g. /dev/tpm0 devicePath = "" # hash algorithms supported by the TPM, e.g. @("SHA256") hashAlgorithms = @() # data source used to fill this object (wmi, direct, pnp) source = "" } return $tpm } End { Write-LeaveFunction } } <# .SYNOPSIS Normalize a TPM specification version .DESCRIPTION Some platforms only expose the major version (e.g. Linux sysfs tpm_version_major = "2"). This function completes a bare major version with ".0" and leaves a full version ("1.2", "2.0") untouched. .EXAMPLE ConvertTo-TpmSpecVersion -InputObject "2" # => 2.0 .EXAMPLE ConvertTo-TpmSpecVersion -InputObject "1.2" # => 1.2 .NOTES General notes #> function ConvertTo-TpmSpecVersion { [CmdletBinding()] [OutputType([String])] Param ( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [AllowNull()][AllowEmptyString()][string]$InputObject ) Begin { Write-EnterFunction } Process { if ([string]::IsNullOrWhiteSpace($InputObject)) { return "" } $version = $InputObject.Trim() if ($version -match '^\d+$') { $version = "$version.0" } return $version } End { Write-LeaveFunction } } <# .SYNOPSIS Convert a TPM PCR bank name to a hash algorithm name .DESCRIPTION Linux exposes the hash algorithms supported by the TPM through the /sys/class/tpm/tpm0/pcr-* directories (e.g. pcr-sha256). This function converts such a bank name to an algorithm name (e.g. SHA256). .EXAMPLE ConvertTo-TpmHashAlgorithm -InputObject "pcr-sha256" # => SHA256 .NOTES General notes #> function ConvertTo-TpmHashAlgorithm { [CmdletBinding()] [OutputType([String])] Param ( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [AllowNull()][AllowEmptyString()][string]$InputObject ) Begin { Write-EnterFunction } Process { if ([string]::IsNullOrWhiteSpace($InputObject)) { return "" } return ($InputObject.Trim() -replace '^pcr-', '').ToUpper() } End { Write-LeaveFunction } } <# .SYNOPSIS Get the TPM (Trusted Platform Module) informations of this computer .DESCRIPTION Base implementation : returns a TPM object with present = $false. Overridden by the Computer.Dict.<OS> dictionaries when the platform supports TPM detection. .EXAMPLE $tpm = Get-ComputerTpm .NOTES General notes #> function Get-ComputerTpm { [CmdletBinding()] [OutputType([PSCustomObject])] Param ( ) Begin { Write-EnterFunction } Process { return New-ComputerTpmObject } End { Write-LeaveFunction } } <# .SYNOPSIS Statically create a new CPU object .DESCRIPTION Think of this function as if it were the constructor of the Cpu object. It returns a CPU object with all properties set to their default values. The Computer.Dict.<OS> dictionaries fill it in. .EXAMPLE $myCpu = New-ComputerCpuObject .NOTES General notes #> function New-ComputerCpuObject { [CmdletBinding()]Param ( ) Begin { Write-EnterFunction } Process { $cpu = [PSCustomObject]@{ # CPU model name, e.g. "Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz" model = "" # number of logical processors (SMT aware, what the OS schedules) cores = 0 # number of physical cores ($null when the platform cannot report it) physicalCores = $null } return $cpu } End { Write-LeaveFunction } } <# .SYNOPSIS Get the computer UUID .DESCRIPTION Base implementation : returns an empty string. Overridden by the Computer.Dict.<OS> dictionaries. .EXAMPLE $uuid = Get-ComputerUuid .NOTES General notes #> function Get-ComputerUuid { [CmdletBinding()] [OutputType([String])] Param ( ) Begin { Write-EnterFunction } Process { return "" } End { Write-LeaveFunction } } <# .SYNOPSIS Get the CPU informations of this computer .DESCRIPTION Base implementation : returns a CPU object with its default values. Overridden by the Computer.Dict.<OS> dictionaries. .EXAMPLE $cpu = Get-ComputerCpu .NOTES General notes #> function Get-ComputerCpu { [CmdletBinding()] [OutputType([PSCustomObject])] Param ( ) Begin { Write-EnterFunction } Process { return New-ComputerCpuObject } End { Write-LeaveFunction } } <# .SYNOPSIS Get the total physical memory of this computer .DESCRIPTION Base implementation : returns 0. Overridden by the Computer.Dict.<OS> dictionaries. .EXAMPLE $memory = Get-ComputerMemory .NOTES General notes #> function Get-ComputerMemory { [CmdletBinding()] [OutputType([Int64])] Param ( ) Begin { Write-EnterFunction } Process { return [Int64]0 } End { Write-LeaveFunction } } <# .SYNOPSIS Get the uptime of this computer .DESCRIPTION Base implementation : returns 0. Overridden by the Computer.Dict.<OS> dictionaries. .EXAMPLE $uptime = Get-ComputerUptime .NOTES General notes #> function Get-ComputerUptime { [CmdletBinding()] [OutputType([Double])] Param ( ) Begin { Write-EnterFunction } Process { return [double]0 } End { Write-LeaveFunction } } |