Blog Post

ITOps Talk Blog
4 MIN READ

PowerShell Basics: Are you using Get-ComputerInfo?

Michael Bender's avatar
Apr 25, 2019

 

Get-ComputerInfo

 

For years, administrators have used commands like Get-WMIObject or Get-CIMInstance, along with other built-in commands, to retrieve computer and system information. This often required multiple commands, and some crafty scripting to get all the information you needed.

 

Well, PowerShell 5.1 brought some relief for admins needing computer specific information with Get-ComputerInfo. With Get-ComputerInfo, an object is returned that contains system and operating system properties. And like all objects in PowerShell, you can work with the data through the pipeline however you see fit.

 

Here's a sample of what you get from Get-ComputerInfo when running without parameters; it will retrieve all of the available properties.

PS > Get-ComputerInfo | more


WindowsBuildLabEx                                       : 17763.1.amd64fre.rs5_release.180914-1434
WindowsCurrentVersion                                   : 6.3
WindowsEditionId                                        : Enterprise
WindowsInstallationType                                 : Client
WindowsInstallDateFromRegistry                          : 11/16/2018 7:25:29 PM
WindowsProductId                                        : 00330-80000-00000-AA933
WindowsProductName                                      : Windows 10 Enterprise
WindowsRegisteredOrganization                           : Microsoft IT
WindowsRegisteredOwner                                  : Microsoft Corp.
WindowsSystemRoot                                       : C:\WINDOWS
WindowsVersion                                          : 1809
BiosCharacteristics                                     : {7, 11, 12, 16...}
BiosBIOSVersion                                         : {MSFT   - 0, 389.2370.769, MSFT - 10000}
BiosBuildNumber                                         :
BiosCaption                                             : 389.2370.769
BiosCodeSet                                             :
BiosCurrentLanguage                                     :
BiosDescription                                         : 389.2370.769
BiosEmbeddedControllerMajorVersion                      : 255
BiosEmbeddedControllerMinorVersion                      : 255
BiosFirmwareType                                        : Uefi
BiosIdentificationCode                                  :
BiosInstallableLanguages                                :
BiosInstallDate                                         :
BiosLanguageEdition                                     :
BiosListOfLanguages                                     :
BiosManufacturer                                        : Microsoft Corporation
BiosName                                                : 389.2370.769
BiosOtherTargetOS                                       :
BiosPrimaryBIOS                                         : True
BiosReleaseDate                                         : 10/1/2018 7:00:00 PM
BiosSeralNumber                                         : 017493481357
BiosSMBIOSBIOSVersion                                   : 389.2370.769
BiosSMBIOSMajorVersion                                  : 3
BiosSMBIOSMinorVersion                                  : 1
BiosSMBIOSPresent                                       : True
BiosSoftwareElementState                                : Running
BiosStatus                                              : OK
BiosSystemBiosMajorVersion                              : 255
BiosSystemBiosMinorVersion                              : 255

 

If you want to see the available properties, simply use Get-Member to review the membership of the object. Currently, the command returns 182 properties in each object for Windows 10 systems. For more on using Get-Member, check out my blog post on ITOpsTalk.com.


PS > Get-ComputerInfo | Get-Member | More


   TypeName: Microsoft.PowerShell.Commands.ComputerInfo

Name                                                    MemberType Definition
----                                                    ---------- ----------
Equals                                                  Method     bool Equals(System.Object obj)
GetHashCode                                             Method     int GetHashCode()
GetType                                                 Method     type GetType()
ToString                                                Method     string ToString()
BiosBIOSVersion                                         Property   string[] BiosBIOSVersion {get;}
BiosBuildNumber                                         Property   string BiosBuildNumber {get;}
BiosCaption                                             Property   string BiosCaption {get;}
BiosCharacteristics                                     Property   uint16[] BiosCharacteristics {get;}
BiosCodeSet                                             Property   string BiosCodeSet {get;}
BiosCurrentLanguage                                     Property   string BiosCurrentLanguage {get;}
...

 

For more granularity, you can use the -Property parameter to search for a singular property such as WindowsCurrentVersion.


PS > Get-ComputerInfo -Property WindowsCurrentVersion

WindowsCurrentVersion
---------------------
6.3

 

Now, let's say you want to find all of the properties related to BIOS, you can use a wildcard like below:


PS > Get-ComputerInfo -Property *BIOS* | FL


BiosCharacteristics                : {7, 11, 12, 16...}
BiosBIOSVersion                    : {MSFT   - 0, 389.2370.769, MSFT - 10000}
BiosBuildNumber                    :
BiosCaption                        : 389.2370.769
BiosCodeSet                        :
BiosCurrentLanguage                :
BiosDescription                    : 389.2370.769
BiosEmbeddedControllerMajorVersion : 255
BiosEmbeddedControllerMinorVersion : 255
BiosFirmwareType                   : Uefi
BiosIdentificationCode             :
BiosInstallableLanguages           :
BiosInstallDate                    :
BiosLanguageEdition                :
BiosListOfLanguages                :
BiosManufacturer                   : Microsoft Corporation
BiosName                           : 389.2370.769
BiosOtherTargetOS                  :
BiosPrimaryBIOS                    : True
BiosReleaseDate                    : 10/1/2018 7:00:00 PM
BiosSeralNumber                    : 017493481357
BiosSMBIOSBIOSVersion              : 389.2370.769
BiosSMBIOSMajorVersion             : 3
BiosSMBIOSMinorVersion             : 1
BiosSMBIOSPresent                  : True
BiosSoftwareElementState           : Running
BiosStatus                         : OK
BiosSystemBiosMajorVersion         : 255
BiosSystemBiosMinorVersion         : 255
BiosTargetOperatingSystem          : 0
BiosVersion                        : MSFT   - 0

 

So all this is great, but there is a catch. Outside of -Property and other common parameters, the command has no built-in support for working against remote machines — no -Computername or -CIMSession properties.

 

Fear not! By using Invoke-Command, this command can be run against one or more remote computers for reporting.

PS C:\Users\Administrator> Invoke-Command -ComputerName 'DC1' -ScriptBlock { Get-ComputerInfo -Property *BIOS* }


BiosCharacteristics                : {4, 7, 9, 11...}
BiosBIOSVersion                    : {VRTUAL - 5001818, BIOS Date: 05/18/18 15:55:38  Ver: 09.00.07, BIOS Date:
                                     05/18/18 15:55:38  Ver: 09.00.07}
BiosBuildNumber                    :
BiosCaption                        : BIOS Date: 05/18/18 15:55:38  Ver: 09.00.07
BiosCodeSet                        :
BiosCurrentLanguage                : enUS
BiosDescription                    : BIOS Date: 05/18/18 15:55:38  Ver: 09.00.07
BiosEmbeddedControllerMajorVersion :
BiosEmbeddedControllerMinorVersion :
BiosFirmwareType                   : Bios
BiosIdentificationCode             :
BiosInstallableLanguages           : 1
BiosInstallDate                    :
BiosLanguageEdition                :
BiosListOfLanguages                : {enUS}
BiosManufacturer                   : American Megatrends Inc.
BiosName                           : BIOS Date: 05/18/18 15:55:38  Ver: 09.00.07
BiosOtherTargetOS                  :
BiosPrimaryBIOS                    : True
BiosReleaseDate                    : 5/17/2018 5:00:00 PM
BiosSeralNumber                    : 6247-7100-6556-1900-0927-2441-21
BiosSMBIOSBIOSVersion              : 090007
BiosSMBIOSMajorVersion             : 2
BiosSMBIOSMinorVersion             : 3
BiosSMBIOSPresent                  : True
BiosSoftwareElementState           : Running
BiosStatus                         : OK
BiosSystemBiosMajorVersion         :
BiosSystemBiosMinorVersion         :
BiosTargetOperatingSystem          : 0
BiosVersion                        : VRTUAL - 5001818
PSComputerName                     : DC1
RunspaceId                         : 3a63fc06-207e-4c64-bd73-819d17b8567e

With this command, you have a lot of scenarios that are candidates for usage. Here's another example for you to try. Let's say you need to have a report of all the hotfixes applied to systems in your environment, and you don't have a centralized reporting tool. 

```PowerShell
PS > Invoke-command -ComputerName 'DC1','DC1','Localhost' -ScriptBlock { Get-ComputerInfo | Select-Object
 -ExpandProperty OSHotFixes } | Sort-Object PSComputername | FT

PSComputerName RunspaceId                           HotFixID  Description     InstalledOn FixComments
-------------- ----------                           --------  -----------     ----------- -----------
DC1            6a0c773e-bf2d-4bcb-a44b-bae82253e062 KB4049065 Update          2/3/2018
DC1            6a0c773e-bf2d-4bcb-a44b-bae82253e062 KB4048953 Security Update 2/3/2018
DC1            2767ad0b-92af-4ab4-8ff9-dfb0b083260b KB4049065 Update          2/3/2018
DC1            2767ad0b-92af-4ab4-8ff9-dfb0b083260b KB4048953 Security Update 2/3/2018
Localhost      3a7efc87-490e-4c0f-8348-076c81c5255c KB4048953 Security Update 2/3/2018
Localhost      3a7efc87-490e-4c0f-8348-076c81c5255c KB4049065 Update          2/3/2018

 

See how we received results back from multiple sources. Then we refined the results using commands like Select-Object and Sort-Object. Now if you wanted this information in a CSV file format, you'd simply pipe the output into Export-CSV like this.



PS > Invoke-command -ComputerName 'DC1','DC1','Localhost' -ScriptBlock { Get-ComputerInfo | select
 -ExpandProperty OSHotFixes } | sort PSComputername | Export-CSV SRV-Updates.csv

I

f you want to go further down the rabbit hole, you could have the -ComputerName parameter populate right out of Active Directory using Get-ADComputer, but that is a post for another time.

 

And there you go - One command for gathering system and operating system information. Try it out!

 

If you want more information on each of these commands, check out the docs below:

Get-ComputerInfo

Invoke-Command

Select-Object

Sort-Object

Updated Apr 24, 2019
Version 1.0