How to Get Computer Information Using PowerShell?

Recently, there have been some issues with some computers; we require computer information to debug more. It is easy to collect various system and hardware details using PowerShell cmdlets. In this tutorial, I will explain how to gather detailed computer information using PowerShell.

Get Computer Information Using PowerShell

By using different PowerShell cmdlets, you can get computer information. Let me show you.

Before executing any specific cmdlets, ensure you have the necessary permissions to run PowerShell scripts on your machine. Open PowerShell with administrative privileges by right-clicking the PowerShell icon and selecting “Run as Administrator.”

Using Get-ComputerInfo Cmdlet

The Get-ComputerInfo cmdlet is the best way to retrieve a comprehensive set of system and operating system properties using PowerShell. This cmdlet consolidates various pieces of information into a single object, making it easier to access and analyze.

Let me show you an example.

Example: Retrieve Basic System Information

To get basic system information of your computer, you can use the following command:

Get-ComputerInfo

This command returns a detailed list of properties, including the operating system version, hardware details, and network configuration.

The exact output of the above cmdlet is in the screenshot below:

Get Computer Information Using PowerShell

Filter Specific Properties

You may not always need all the information returned by Get-ComputerInfo. To filter specific properties, use the Select-Object cmdlet like below:

Get-ComputerInfo | Select-Object CsName, WindowsVersion, OsArchitecture, CsProcessors

In this example, we retrieve only the computer name, Windows version, OS architecture, and processor details.

Check out How to Enable WinRM (Windows Remote Management) Using PowerShell?

Gather Information from Remote Computers

Sometimes, you may need to gather information from remote computers.

PowerShell allows you to collect information from remote computers in your network using the Invoke-Command cmdlet. This is particularly useful for system administrators managing multiple machines.

Example: Collect Information from a Remote Computer

First, ensure that PowerShell Remoting is enabled on the target computer. Then, use the following command:

Invoke-Command -ComputerName "RemotePC01" -ScriptBlock { Get-ComputerInfo }

Replace "RemotePC01" with the name of the remote computer. This command executes Get-ComputerInfo on the remote machine and returns the results to your local session.

Using CIM and WMI Cmdlets

For more granular control, you can use CIM (Common Information Model) and WMI (Windows Management Instrumentation) cmdlets. These cmdlets provide access to a broader range of system information.

Let me show you an example.

Example: Retrieve BIOS Information

To get BIOS information, use the Get-CimInstance cmdlet:

Get-CimInstance -ClassName Win32_BIOS

This command returns details about the BIOS, including the manufacturer, version, and release date.

Example: Collect CPU Information

To gather detailed CPU information, use the following PowerShell command:

Get-CimInstance -ClassName Win32_Processor | Select-Object Name, NumberOfCores, NumberOfLogicalProcessors, MaxClockSpeed

This command retrieves the CPU name, number of cores, number of logical processors, and maximum clock speed.

Check out Create Local Users in Windows Using PowerShell

Automate The Process of Collecting Computer Information

Now, let me show you how to automate the process of collecting computer information.

For large environments, manually running these commands on each machine can be time-consuming. Instead, you can automate the process using a script.

You can write a PowerShell script to collect information from multiple computers.

Create a script named Collect-ComputerInfo.ps1 with the following content:

$computers = @("PC01", "PC02", "PC03")

foreach ($computer in $computers) {
    $info = Invoke-Command -ComputerName $computer -ScriptBlock { Get-ComputerInfo }
    $info | Select-Object CsName, WindowsVersion, OsArchitecture, CsProcessors | Export-Csv -Path "$computer-info.csv" -NoTypeInformation
}

Replace @("PC01", "PC02", "PC03") with the names of your computers. This script collects the specified information and exports it to CSV files named after each computer.

Check out Create a Registry Key with PowerShell If It Does Not Exist

Troubleshooting Common Issues

Now, let me show you some common issues and fixes that you might get while working with these PowerShell scripts.

Issue: Access Denied Errors

If you encounter access denied errors, ensure that you have the necessary administrative privileges and that PowerShell Remoting is enabled on the target computers. You can enable PowerShell Remoting with the following command:

Enable-PSRemoting -Force

Issue: Network Connectivity Problems

Ensure that the target computers are reachable over the network and that there are no firewall rules blocking PowerShell Remoting. You can test connectivity using the Test-Connection cmdlet:

Test-Connection -ComputerName "RemotePC01"

Conclusion

In this tutorial, I explained how to get computer information using PowerShell. By using cmdlets like Get-ComputerInfo, Get-CimInstance, and Invoke-Command, you can automate the collection of system data across multiple machines, saving time and reducing the risk of manual errors. Do let me know if this tutorial helps you.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.