# Trouble displaying sizes of multiple drives

**URL:** <https://forums.powershell.org/t/trouble-displaying-sizes-of-multiple-drives/13126>\
**Category:** PowerShell Help\
**Created:** [September 11, 2019, 5:50pm UTC](https://forums.powershell.org/t/trouble-displaying-sizes-of-multiple-drives/13126 "2019-09-11T17:50:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gary-pietila](https://avatars.discourse-cdn.com/v4/letter/g/f4b2a3/32.png) [@gary-pietila](https://forums.powershell.org/u/gary-pietila)\
**Post date:** [September 11, 2019, 5:50pm UTC](https://forums.powershell.org/t/trouble-displaying-sizes-of-multiple-drives/13126/1 "2019-09-11T17:50:18Z")

</div>

I am trying to display the drive letter & drive size of multiple drives on one or more servers. So far I am testing on one server only.

When I run this against a server with 2 local drives (one with a capacity of 40 GB & the other with a capacity of 1821 GB) only the first drive is shown & the size is incorrect:

ComputerName : security5  
OSVersion : 6.1.7601  
SPVersion : 1  
OSBuild : 7601  
Manufacturer : Dell Inc.  
Model : PowerEdge 2950  
Procs : 1  
Cores : 4  
RAM : 3.99505615234375  
Arch : 64  
SysDriveFreeSpace : 9670627328  
Disk1 ID : C:  
Disk1 Size : 235.48  
Disk2 ID :  
Disk2 Size :  
Disk3 ID :  
Disk3 Size :  
Disk4 ID :  
Disk4 Size :

I don’t get any errors when I run this. Any better way of doing this?

&nbsp;

> <https://gist.github.com/pietilag/e5470d99362e754b7d219959f994aa3e>

&nbsp;

---

<div class="post-metadata">

**Author:** ![aaron-hardy](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@aaron-hardy](https://forums.powershell.org/u/aaron-hardy)\
**Post date:** [September 14, 2019, 1:26pm UTC](https://forums.powershell.org/t/trouble-displaying-sizes-of-multiple-drives/13126/2 "2019-09-14T13:26:42Z")

</div>

Try this - make drive population dynamic by looping through them and adding to the PSCustomObject:

```
$obj = [pscustomobject]@{
    'ComputerName' = $computer
    'OSVersion' = $os.version
    'SPVersion' = $os.servicepackmajorversion
    'OSBuild' = $os.buildnumber
    'Manufacturer' = $cs.manufacturer
    'Model' = $cs.model
    'Procs' =$cs.numberofprocessors
    'Cores' = $cs.numberoflogicalprocessors
    'RAM' = ($cs.totalphysicalmemory / 1GB)
    'Arch' = $proc.addresswidth
    'SysDriveFreeSpace' = $drive.freespace
}

$diskCounter = 0

foreach ($logicalDrive in $drives) {  
$obj | Add-Member -MemberType NoteProperty -Name (‘Disk{0}Id’ -f ($diskCounter + 1)) -Value $logicalDrive.DeviceId  
$obj | Add-Member -MemberType NoteProperty -Name (‘Disk{0}Size’ -f ($diskCounter + 1)) -Value $logicalDrive.Capacity

```
$diskCounter += 1

```

}

Write-Output $obj
```

Edit: Sorry for multiple edits; formatting issues.

---

<div class="post-metadata">

**Author:** ![aaron-hardy](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@aaron-hardy](https://forums.powershell.org/u/aaron-hardy)\
**Post date:** [September 14, 2019, 11:31pm UTC](https://forums.powershell.org/t/trouble-displaying-sizes-of-multiple-drives/13126/3 "2019-09-14T23:31:30Z")

</div>

A little more explaining:

Most of your remote queries are using CIM cmdlets with a session object, except for the one below, and this is likely the reason why results for only one drive appears when running against other systems. Do you only have one drive on your system?

When assigning the `$drives` variable, you are using `Get-WmiObject` **without** a `-ComputerName` parameter, which means it is actually running against your local computer:

```
$drives = Get-WmiObject -Class Win32_logicaldisk-Filter"DriveType = '3'" | ...
```

Change it to CIM as the other cmdlets:

```
$drives = Get-CimInstance -CimSession $session -ClassName Win32_LogicalDisk-Filter"DriveType = '3'" | ...
```

By making these changes, and from my previous response, you should get the expected output.

Edit: Sorry, formatting issues again.

---

<div class="post-metadata">

**Author:** ![gary-pietila](https://avatars.discourse-cdn.com/v4/letter/g/f4b2a3/32.png) [@gary-pietila](https://forums.powershell.org/u/gary-pietila)\
**Post date:** [September 16, 2019, 11:16pm UTC](https://forums.powershell.org/t/trouble-displaying-sizes-of-multiple-drives/13126/4 "2019-09-16T23:16:13Z")

</div>

That worked great. The only thing I had to change was $logicalDrive.Capacity to $logicalDrive.Size

&nbsp;

Thank you.

---

<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:31pm UTC](https://forums.powershell.org/t/trouble-displaying-sizes-of-multiple-drives/13126/5 "2024-05-16T20:31:21Z")

</div>


