Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Use PowerShell and WMI to Get CPU Information

Suppose you want to get some information about the CPU in your computer. Can you remember which Control Panel utility will provide that information? Is it My Computer or System? Unfortunately, like a department store that keeps moving merchandise around to confuse you into thinking they have something new, with each new version Microsoft keeps rearranging Windows operating system utilities.

PowerShell is a more powerful replacement for the command shell. WMI (Windows Management Interface) is part of the Windows operating system that can be used to gather system statistics, monitor system health, and manage system components. If you use a PowerShell script to access WMI you can always get the information you want no mater how they rearrange Control Panel.

The best way to use PowerShell is to create and run scripts. Once you've written a script, you can save it to use again, on your machine or a friends machine. Because of PowerShell's awesome power, its execution policy may not allow you to run scripts. To change PowerShell's execution policy, you'll need to run PowerShell as an administrator.

To run PowerShell, in the task bar Search box, type "PowerShell". In the menu that appears, right-click on Windows PowerShell, and in the menu that appears, select "Run as administrator". Enter the following command after the PS prompt:

PS C:\> Set-ExecutionPolicy Unrestricted

In the User Account Control warning box that appears, click on the [Yes] button. In the PowerShell window the message "... Do you want to change the execution policy?" will appear. Enter Y and press [Enter].

The best way to run PowerShell scripts is to create a shortcut on your desktop, in the shortcut's location of item for shortcut textbox, enter:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit

Note: If you have Windows 8.1 or Windows Server 2012 R2, on your machine along with PowerShell, you have PowerShell version 2, so you may want a different shortcut path. However, you can still use PowerShell version 1. Note the -NoExit switch at the end of the path, this keeps the PowerShell window from closing before you can see the returned results.

The Get-WMIObject Cmdlet gets instances of WMI classes. WMI classes are the software objects that query the system's various devices and system resources. To use PowerShell with WMI, write a script that uses the Get-WMIObject Cmdlet.

To create a PowerShell script open a basic ASCII text editor like Windows Notepad and type in the following comand.

(Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name

Save the file extension .ps1 for example getCompname.ps1. To run the script, drag it to the shortcut that you created above.

The above command uses the WMI interface's Win32_ComputerSystem class to access the local computer's name. To close the PowerShell window, type exit at the prompt.

Now to get information about the CPU in your computer, create another script named say, cpuinfo.ps1, and enter the following command, replacing COMPUTER-NAME with your computer's name returned by the script above.

Get-WmiObject Win32_processor -ComputerName COMPUTER-NAME
Information returned by the Win32_processor class

Shown above is an example of the information returned by the Win32_processor class.

RSS Feed RSS Feed


Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2018 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268