PowerShell Basics: Are you using Get-ComputerInfo?
Published Apr 24 2019 11:00 PM 79.1K Views
Microsoft

 

Get-ComputerInfoGet-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

11 Comments
Brass Contributor
well this is a "til" moment.
Microsoft

@Tony Roth Glad to hear we could help you learn a new tool today. Let me know what you think of it when you give it a shot!

Brass Contributor

Around the office we were all kinda laughing about all the different ways we did things within powershell in the past to get the same result as a single cmdlet!  

 

thanks

Copper Contributor

The only down side is that it is significantly sloweerrrrrrr than CIM/WMI cmdlets, but it's definitely much more user friendly. Even if you specify a single property it will still gather all information, but filter for the specified property. This makes the cmdlet take the same amount time to process even though you're only querying for 1 property. It's great if you can't remember the specific cim/wmi class though!

Screen Shot 2019-04-25 at 8.30.32 PM.png

Windows Powershell 5.1

Brass Contributor

@Phatmandrake your last sentence nails it!

Microsoft

@Phatmandrake I definitely caught that during my usage, and that is great feedback. I will pass it along. Also, I hope you consider adding it as an issue through the feedback link at the bottom of the documentation page for the command. This will get fed into the product team responsible for the cmdlet.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-computerinfo?...

 

While I haven't tried this, it would work in situations where you are collecting data for use later. Using the -asjob parameter might be an option to background the processing.

 

Thanks and have a great day!

Microsoft

@Tony Roth I Know!!!! I've taught PowerShell for a few years, and the things we covered to do what is in the command are huge. Not that those other techniques aren't needed; they definitely are. It's just that so many common items are in Get-ComputerInfo. 

 

I look forward to hearing how you use it in the future!

Copper Contributor

@Michael Bender Having a little trouble getting this working against Win10 1809 ?  Dont see any specific exclusions for that version in the docs and I've got PS 5.1 - 1809 still supported in Enterprise version for quite a while - any particular guidance for using against 1809 ?

Copper Contributor

I have been using this command for two years now. It's great. I wish there was a set- option though. I usually deal with that in the common way by scripting it but a set command would be nice.

Copper Contributor

I am researching this command but in a way to report more than one operating system on one machine so that it can be determined if the security control is met.  The security control states that only one OS is permitted on any one asset.  If I can use powershell to return the results of one or more I can have the audit pass or fail.

Am I looking at the right powershell command or is there another command I should be looking at.

 

Thanks - PJ

Copper Contributor

Hey @Michael Bender that last line appears to be just about what I'm looking for, either to pull from ALL AD computers or to pull from a list of computers or IPs.

 

Could you assist with that? Sending you a message as well.

Version history
Last update:
‎Apr 24 2019 07:59 AM
Updated by: