Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,58 @@ ms.assetid: 9e7b6a2d-34f7-4731-a92c-8b3382eb51bb
---
# Collecting Information About Computers

**Get-WmiObject** is the most important cmdlet for general system management tasks. All critical subsystem settings are exposed through WMI. Furthermore, WMI treats data as objects that are in collections of one or more items. Because Windows PowerShell also works with objects and has a pipeline that allows you to treat single or multiple objects in the same way, generic WMI access allows you to perform some advanced tasks with very little work.
Cmdlets from **CimCmdlets** module are the most important cmdlets for general system management tasks.
All critical subsystem settings are exposed through WMI.
Furthermore, WMI treats data as objects that are in collections of one or more items.
Because Windows PowerShell also works with objects and has a pipeline that allows you to treat single or multiple objects in the same way, generic WMI access allows you to perform some advanced tasks with very little work.

The following examples demonstrate how to collect specific information by using **Get-WmiObject** against an arbitrary computer. We specify the **ComputerName** parameter with the dot value (**.**), which represents the local computer. You can specify a name or IP address associated with any computer you can reach through WMI. To retrieve information about the local computer, you could omit the **-ComputerName.**
The following examples demonstrate how to collect specific information by using `Get-CimInstance` against an arbitrary computer.
We specify the **ComputerName** parameter with the dot value (**.**), which represents the local computer.
You can specify a name or IP address associated with any computer you can reach through WMI.
To retrieve information about the local computer, you could omit the **ComputerName** parameter.

### Listing Desktop Settings

We'll begin with a command that collects information about the desktops on the local computer.

```powershell
Get-WmiObject -Class Win32_Desktop -ComputerName .
Get-CimInstance -ClassName Win32_Desktop -ComputerName .
```

This returns information for all desktops, whether they are in use or not.

> [!NOTE]
> Information returned by some WMI classes can be very detailed, and often include metadata about the WMI class. Because most of these metadata properties have names that begin with a double underscore, you can filter the properties using Select-Object. Specify only properties that begin with alphabetic characters by using **[a-z]*** as the Property value. For example:
> Information returned by some WMI classes can be very detailed, and often include metadata about the WMI class.
Because most of these metadata properties have names that begin with **Cim**, you can filter the properties using `Select-Object`.
Specify the **-ExcludeProperty** parameter with "Cim*" as the value.
For example:

```powershell
Get-WmiObject -Class Win32_Desktop -ComputerName . | Select-Object -Property [a-z]*
Get-CimInstance -ClassName Win32_Desktop -ComputerName . | Select-Object -ExcludeProperty "CIM*"
```

To filter out the metadata, use a pipeline operator (|) to send the results of the Get-WmiObject command to `Select-Object -Property [a-z]*`.
To filter out the metadata, use a pipeline operator (|) to send the results of the `Get-CimInstance` command to `Select-Object -ExcludeProperty "CIM*"`.

### Listing BIOS Information

The WMI Win32_BIOS class returns fairly compact and complete information about the system BIOS on the local computer:
The WMI **Win32_BIOS** class returns fairly compact and complete information about the system BIOS on the local computer:

```powershell
Get-WmiObject -Class Win32_BIOS -ComputerName .
Get-CimInstance -ClassName Win32_BIOS -ComputerName .
```

### Listing Processor Information

You can retrieve general processor information by using WMI's **Win32_Processor** class, although you will likely want to filter the information:

```powershell
Get-WmiObject -Class Win32_Processor -ComputerName . | Select-Object -Property [a-z]*
Get-CimInstance -ClassName Win32_Processor -ComputerName . | Select-Object -ExcludeProperty "CIM*"
```

For a generic description string of the processor family, you can just return the **SystemType** property:

```
PS> Get-WmiObject -Class Win32_ComputerSystem -ComputerName . | Select-Object -Property SystemType
```powershell
Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName . | Select-Object -Property SystemType

SystemType
----------
Expand All @@ -57,127 +66,130 @@ X86-based PC

### Listing Computer Manufacturer and Model

Computer model information is also available from **Win32_ComputerSystem**. The standard displayed output will not need any filtering to provide OEM data:
Computer model information is also available from **Win32_ComputerSystem**.
The standard displayed output will not need any filtering to provide OEM data:

```powershell
Get-CimInstance -ClassName Win32_ComputerSystem
```
PS> Get-WmiObject -Class Win32_ComputerSystem

Domain : WORKGROUP
Manufacturer : Compaq Presario 06
Model : DA243A-ABA 6415cl NA910
Name : MyPC
PrimaryOwnerName : Jane Doe
TotalPhysicalMemory : 804765696
```output
Name PrimaryOwnerName Domain TotalPhysicalMemory Model Manufacturer
---- ---------------- ------ ------------------- ----- ------------
MyPC Jane Doe WORKGROUP 804765696 DA243A-ABA 6415cl NA910 Compaq Presario 06
```

Your output from commands such as this, which return information directly from some hardware, is only as good as the data you have. Some information is not correctly configured by hardware manufacturers and may therefore be unavailable.
Your output from commands such as this, which return information directly from some hardware, is only as good as the data you have.
Some information is not correctly configured by hardware manufacturers and may therefore be unavailable.

### Listing Installed Hotfixes

You can list all installed hotfixes by using **Win32_QuickFixEngineering**:

```powershell
Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName .
Get-CimInstance -ClassName Win32_QuickFixEngineering -ComputerName .
```

This class returns a list of hotfixes that looks like this:

```output
Description : Update for Windows XP (KB910437)
FixComments : Update
HotFixID : KB910437
Install Date :
InstalledBy : Administrator
InstalledOn : 12/16/2005
Name :
ServicePackInEffect : SP3
Status :
Source Description HotFixID InstalledBy InstalledOn PSComputerName
------ ----------- -------- ----------- ----------- --------------
Security Update KB4048951 Administrator 12/16/2017 .
```

For more succinct output, you may want to exclude some properties. Although you can use the **Get-WmiObject's Property** parameter to choose only the **HotFixID**, doing so will actually return more information, because all the metadata is displayed by default:
For more succinct output, you may want to exclude some properties.
Although you can use the `Get-CimInstance`'s **Property** parameter to choose only the **HotFixID**, doing so will actually return more information, because all the metadata is displayed by default:

```
PS> Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName . -Property HotFixID

HotFixID : KB910437
__GENUS : 2
__CLASS : Win32_QuickFixEngineering
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
```powershell
Get-CimInstance -ClassName Win32_QuickFixEngineering -ComputerName . -Property HotFixID
```

The additional data is returned, because the Property parameter in **Get-WmiObject** restricts the properties returned from WMI class instances, not the object returned to Windows PowerShell. To reduce the output, use **Select-Object**:
```output
PSShowComputerName : True
InstalledOn :
Caption :
Description :
InstallDate :
Name :
Status :
CSName :
FixComments :
HotFixID : KB4048951
InstalledBy :
ServicePackInEffect :
PSComputerName : .
CimClass : root/cimv2:Win32_QuickFixEngineering
CimInstanceProperties : {Caption, Description, InstallDate, Name...}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties
```

The additional data is returned, because the Property parameter in `Get-CimInstance` restricts the properties returned from WMI class instances, not the object returned to Windows PowerShell.
To reduce the output, use `Select-Object`:

```powershell
Get-CimInstance -ClassName Win32_QuickFixEngineering -ComputerName . -Property HotFixId | Select-Object -Property HotFixId
```
PS> Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName . -Property HotFixId | Select-Object -Property HotFixId

```output
HotFixId
--------
KB910437
KB4048951
```

### Listing Operating System Version Information

The **Win32_OperatingSystem** class properties include version and service pack information. You can explicitly select only these properties to get a version information summary from **Win32_OperatingSystem**:
The **Win32_OperatingSystem** class properties include version and service pack information.
You can explicitly select only these properties to get a version information summary from **Win32_OperatingSystem**:

```powershell
Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-Object -Property BuildNumber,BuildType,OSType,ServicePackMajorVersion,ServicePackMinorVersion
Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName . | Select-Object -Property BuildNumber,BuildType,OSType,ServicePackMajorVersion,ServicePackMinorVersion
```

You can also use wildcards with the **Select-Object's Property** parameter. Because all the properties beginning with either **Build** or **ServicePack** are important to use here, we can shorten this to the following form:
You can also use wildcards with the `Select-Object`'s **Property** parameter.
Because all the properties beginning with either **Build** or **ServicePack** are important to use here, we can shorten this to the following form:

```powershell
Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName . | Select-Object -Property Build*,OSType,ServicePack*
```
PS> Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-Object -Property Build*,OSType,ServicePack*

BuildNumber : 2600
BuildType : Uniprocessor Free
```output
BuildNumber : 16299
BuildType : Multiprocessor Free
OSType : 18
ServicePackMajorVersion : 2
ServicePackMajorVersion : 0
ServicePackMinorVersion : 0
```

### Listing Local Users and Owner

Local general user information—number of licensed users, current number of users, and owner name—can be found with a selection of **Win32_OperatingSystem** properties. You can explicitly select the properties to display like this:
Local general user information — number of licensed users, current number of users, and owner name — can be found with a selection of **Win32_OperatingSystem** class' properties.
You can explicitly select the properties to display like this:

```powershell
Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-Object -Property NumberOfLicensedUsers,NumberOfUsers,RegisteredUser
Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName . | Select-Object -Property NumberOfLicensedUsers,NumberOfUsers,RegisteredUser
```

A more succinct version using wildcards is:

```powershell
Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-Object -Property *user*
Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName . | Select-Object -Property *user*
```

### Getting Available Disk Space

To see the disk space and free space for local drives, you can use the WMI Win32_LogicalDisk class. You need to see only instances with a DriveType of 3—the value WMI uses for fixed hard disks.

```
PS> Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName .
To see the disk space and free space for local drives, you can use the Win32_LogicalDisk WMI class.
You need to see only instances with a DriveType of 3 — the value WMI uses for fixed hard disks.

DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 65541357568
Size : 203912880128
VolumeName : Local Disk
```powershell
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" -ComputerName .

DeviceID : Q:
DriveType : 3
ProviderName :
FreeSpace : 44298250240
Size : 122934034432
VolumeName : New Volume
DeviceID DriveType ProviderName VolumeName Size FreeSpace PSComputerName
-------- --------- ------------ ---------- ---- --------- --------------
C: 3 Local Disk 203912880128 65541357568 .
Q: 3 New Volume 122934034432 44298250240 .

PS> Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName . | Measure-Object -Property FreeSpace,Size -Sum | Select-Object -Property Property,Sum
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" -ComputerName . | Measure-Object -Property FreeSpace,Size -Sum | Select-Object -Property Property,Sum

Property Sum
-------- ---
Expand All @@ -187,26 +199,27 @@ Size 326846914560

### Getting Logon Session Information

You can get general information about logon sessions associated with users through the WMI Win32_LogonSession class:
You can get general information about logon sessions associated with users through the **Win32_LogonSession** WMI class:

```powershell
Get-WmiObject -Class Win32_LogonSession -ComputerName .
Get-CimInstance -ClassName Win32_LogonSession -ComputerName .
```

### Getting the User Logged on to a Computer

You can display the user logged on to a particular computer system using Win32_ComputerSystem. This command returns only the user logged on to the system desktop:
You can display the user logged on to a particular computer system using Win32_ComputerSystem.
This command returns only the user logged on to the system desktop:

```powershell
Get-WmiObject -Class Win32_ComputerSystem -Property UserName -ComputerName .
Get-CimInstance -ClassName Win32_ComputerSystem -Property UserName -ComputerName .
```

### Getting Local Time from a Computer

You can retrieve the current local time on a specific computer by using the WMI Win32_LocalTime class. Because this class by default displays all metadata, you may want to filter it using **Select-Object**:
You can retrieve the current local time on a specific computer by using the **Win32_LocalTime** WMI class.

```
PS> Get-WmiObject -Class Win32_LocalTime -ComputerName . | Select-Object -Property [a-z]*
```powershell
Get-CimInstance -ClassName Win32_LocalTime -ComputerName .

Day : 15
DayOfWeek : 4
Expand All @@ -217,19 +230,22 @@ Month : 6
Quarter : 2
Second : 52
WeekInMonth : 3
Year : 2006
Year : 2017
PSComputerName : .
```

### Displaying Service Status

To view the status of all services on a specific computer, you can locally use the **Get-Service** cmdlet as mentioned earlier. For remote systems, you can use the WMI Win32_Service class. If you also use **Select-Object** to filter the results to **Status**, **Name**, and **DisplayName**, the output format will be almost identical to that from **Get-Service**:
To view the status of all services on a specific computer, you can locally use the `Get-Service` cmdlet.
For remote systems, you can use the **Win32_Service** WMI class.
If you also use `Select-Object` to filter the results to **Status**, **Name**, and **DisplayName**, the output format will be almost identical to that from `Get-Service`:

```powershell
Get-WmiObject -Class Win32_Service -ComputerName . | Select-Object -Property Status,Name,DisplayName
Get-CimInstance -ClassName Win32_Service -ComputerName . | Select-Object -Property Status,Name,DisplayName
```

To allow the complete display of names for the occasional services with extremely long names, you may want to use **Format-Table** with the **AutoSize** and **Wrap** parameters, to optimize column width and allow long names to wrap instead of being truncated:
To allow the complete display of names for the occasional services with extremely long names, you may want to use `Format-Table` with the **AutoSize** and **Wrap** parameters, to optimize column width and allow long names to wrap instead of being truncated:

```powershell
Get-WmiObject -Class Win32_Service -ComputerName . | Format-Table -Property Status,Name,DisplayName -AutoSize -Wrap
Get-CimInstance -ClassName Win32_Service -ComputerName . | Format-Table -Property Status,Name,DisplayName -AutoSize -Wrap
```