# Get-cimInstance

**URL:** <https://forums.powershell.org/t/get-ciminstance/10062>\
**Category:** PowerShell Help\
**Created:** [February 1, 2018, 7:48am UTC](https://forums.powershell.org/t/get-ciminstance/10062 "2018-02-01T07:48:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/yeta/32/1922_2.png) [@yeta](https://forums.powershell.org/u/yeta)\
**Post date:** [February 1, 2018, 7:48am UTC](https://forums.powershell.org/t/get-ciminstance/10062/1 "2018-02-01T07:48:04Z")

</div>

Greetings,  
When I execute this code, I am getting an ‘Invalid query’ powershell error. Have I formatted the code correctly?

Get-CimInstance -ClassName cim\_storagevolume -Filter “DriveLetter=‘C:’”

---

<div class="post-metadata">

**Author:** ![will-anderson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/will-anderson/32/234_2.png) [@will-anderson](https://forums.powershell.org/u/will-anderson)\
**Post date:** [February 1, 2018, 8:11am UTC](https://forums.powershell.org/t/get-ciminstance/10062/2 "2018-02-01T08:11:45Z")

</div>

That particular class doesn’t appear to like filtering via the Get-CimInstance cmdlet. I’ll ask around to see if someone can explain exactly why.

In the meantime, I’ve found that this works.

```
(Get-CimInstance -ClassName Cim_StorageVolume).where({$PSItem.DriveLetter -eq 'C:'})
```

---

<div class="post-metadata">

**Author:** ![simbrook](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@simbrook](https://forums.powershell.org/u/simbrook)\
**Post date:** [February 1, 2018, 8:16am UTC](https://forums.powershell.org/t/get-ciminstance/10062/3 "2018-02-01T08:16:41Z")

</div>

This also works

Get-CimInstance -ClassName cim\_storagevolume | where driveletter -eq “C:”

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [February 1, 2018, 8:17am UTC](https://forums.powershell.org/t/get-ciminstance/10062/4 "2018-02-01T08:17:00Z")

</div>

I’m not able to get it to filter either, I did something similar to Will to get the results. Many ways to skin the PowerShell cat!

```
Get-CimInstance -ClassName CIM_StorageVolume | where driveletter -eq "C:"
```

ETA: Beat me by a min Simon! 😉

---

<div class="post-metadata">

**Author:** ![will-anderson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/will-anderson/32/234_2.png) [@will-anderson](https://forums.powershell.org/u/will-anderson)\
**Post date:** [February 1, 2018, 8:24am UTC](https://forums.powershell.org/t/get-ciminstance/10062/5 "2018-02-01T08:24:30Z")

</div>

Simon is pretty quick. 😉

Surprisingly, Where-Object does appear to be faster in this instance too.

```
PS C:\WINDOWS\system32> Measure-Command {(Get-CimInstance -ClassName Cim_StorageVolume).where({$PSItem.DriveLetter -eq 'C:'})}
Measure-Command {Get-CimInstance -ClassName Cim_StorageVolume | Where-Object DriveLetter -EQ 'C:'}

Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 50
Ticks : 504126
TotalDays : 5.83479166666667E-07
TotalHours : 1.40035E-05
TotalMinutes : 0.00084021
TotalSeconds : 0.0504126
TotalMilliseconds : 50.4126

Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 28
Ticks : 284677
TotalDays : 3.29487268518518E-07
TotalHours : 7.90769444444444E-06
TotalMinutes : 0.000474461666666667
TotalSeconds : 0.0284677
TotalMilliseconds : 28.4677
```

---

<div class="post-metadata">

**Author:** ![will-anderson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/will-anderson/32/234_2.png) [@will-anderson](https://forums.powershell.org/u/will-anderson)\
**Post date:** [February 1, 2018, 8:41am UTC](https://forums.powershell.org/t/get-ciminstance/10062/6 "2018-02-01T08:41:13Z")

</div>

Explanation per Mr. Richard Siddaway - who is way better at WMI things than I am:

> The class
> 
> > **[CIM\\\_StorageVolume class](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/iscsitarg/cim-storagevolume?redirectedfrom=MSDN)**
> >
> > A StorageVolume is a StorageExtent that is published for use outside of the scoping System.
> 
> doesn’t appear to have a DriveLetter property so filter won’t work
> 
> Interestingly
> 
> PS\> Get-CimInstance -ClassName cim\_storagevolume | gm
> 
> TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32\_Volume
> 
> Win32\_volume derives from cim\_storagevolume
> 
> PS\> Get-WmiObject -Class Win32\_volume | select -f 1 | select -expand \_\_derivation
> 
> CIM\_StorageVolume
> 
> CIM\_StorageExtent
> 
> CIM\_LogicalDevice
> 
> CIM\_LogicalElement
> 
> CIM\_ManagedSystemElement
> 
> Looks to me like the call to CIM\_StorageVolume actually ends up calling Win32\_Volume
> 
> CIM\_StorageVolume doesn’t appear to have a driveletter property so you can’t filter on it BUT Win32\_Volume does have a drive letter property which is what is displayed
> 
> I always recommend using the Win32-\* classes rather than the CIM\_ classes because the Win32\_\* classes were designed fro Windows whereas the CIM\_\* classes are generic

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [February 1, 2018, 8:58am UTC](https://forums.powershell.org/t/get-ciminstance/10062/7 "2018-02-01T08:58:23Z")

</div>

“doesn’t appear to have a DriveLetter property so filter won’t work”

Pardon my ignorance, if that is the case then why would the below commands return a value if their is not a property? Are they something else than properties?

```
Get-CimInstance -ClassName CIM_StorageVolume | select driveletter
```

```
Get-CimInstance -ClassName CIM_StorageVolume | where driveletter -eq "C:"
```

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [February 1, 2018, 10:15am UTC](https://forums.powershell.org/t/get-ciminstance/10062/8 "2018-02-01T10:15:29Z")

</div>

Notice the type being returned

PS\> Get-CimInstance -ClassName CIM\_StorageVolume | gm

TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32\_Volume

When you’re calling CIM\_StorageVolume your getting back Win32\_Volume which is derived from CIM\_StorageVolume. Win32\_Volume HAS a DriveLetter property which is why your use of Select\_Object and Where-Object works

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [February 1, 2018, 10:56am UTC](https://forums.powershell.org/t/get-ciminstance/10062/9 "2018-02-01T10:56:49Z")

</div>

So select/where can read what is in win32\_volume but -filter is unable to?

---

<div class="post-metadata">

**Author:** ![jb-lewis](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@jb-lewis](https://forums.powershell.org/u/jb-lewis)\
**Post date:** [February 1, 2018, 1:43pm UTC](https://forums.powershell.org/t/get-ciminstance/10062/10 "2018-02-01T13:43:32Z")

</div>

What I think they are saying is that the CIM\_ class call is actually fulfilled by making a call to Win32\_Volume behind the scenes, but apparently after an attempt is made to apply the filter. When you query CIM\_StorageVolume, and provide a filter it is failing because CIM\_StorageVolume doesn’t have that DriveLetter property, and I’ll even go out on a limb a guess that it actually has _no_ properties. The data returned has properties thanks to Win32\_Volume. So, when I do a Get-CIMInstance Win32\_Volume -Filter ‘DriveLetter = “E:”’, I get back info just for the E drive.

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [February 2, 2018, 4:55am UTC](https://forums.powershell.org/t/get-ciminstance/10062/11 "2018-02-02T04:55:33Z")

</div>

COM\_StorageVolume does have properties

Get-CimClass Win32\_Volume  
and  
Get-CimClass CIM\_storagevolume

will show the difference

DriveLetters are a Windows thing which is probably why they aren’t present on CIM\_SrorageVolume which is meant to be generic

---

<div class="post-metadata">

**Author:** ![yeta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/yeta/32/1922_2.png) [@yeta](https://forums.powershell.org/u/yeta)\
**Post date:** [February 2, 2018, 7:56am UTC](https://forums.powershell.org/t/get-ciminstance/10062/12 "2018-02-02T07:56:03Z")

</div>

Thanks all for your great insights on the CIM\_StorageVolume and Win32\_Volume…

---

<div class="post-metadata">

**Author:** ![yeta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/yeta/32/1922_2.png) [@yeta](https://forums.powershell.org/u/yeta)\
**Post date:** [February 2, 2018, 7:59am UTC](https://forums.powershell.org/t/get-ciminstance/10062/13 "2018-02-02T07:59:50Z")

</div>

Thanks Richard…by the way, your book ‘Powershell and WMI’ is a great resource. I’m really enjoying the book…

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/get-ciminstance/10062/14 "2024-05-16T20:37:13Z")

</div>

Closed on May 16, 2024, 8:37pm UTC


