Get-WmiObject Win32_LogicalDisk: The format of strings for computername etc

What is the format suppose to be for the strings which represent computer names and the partition?

The reason why I am asking is that my free space is always returning zero on the powershell session? This is not correct, because the real free space is 60 gigs.

This is the code used

$ip = “”
$partition = “DeviceID =‘E’”
$description = “backup_server”

$ConvertToGB = (1024 * 1024 * 1024)

$disk = Get-WmiObject Win32_LogicalDisk -ComputerName $ip -Filter $partition | Select-Object Size,FreeSpace

$ip + $partition + $description + ([math]::round(($disk.Size / $ConvertToGB),2)) + “GB” + “,” + ([math]::round((($disk.FreeSpace / $ConvertToGB)),2)) + “GB”

Can someone please advise if the something is needed to be added to the strings for the computer name and partition name? Or perhaps special characters or extra commas or quotes etc???

I advice You do not write such a long code if you get any error ;^)
If You launch just small sample - Get-WmiObject Win32_LogicalDisk -ComputerName $ip, you will see that DeviceID is “E:” but not “E”, do not get $null in $disk variable and do not get FreeSize=0Gb

AS Noted above the DeviceId MUST include the :

DeviceId is the key property for the class. The correct usage is shown on the Path and __Relpath properties

Looking at you code you can make some improvements to take advantage of PowerShell’s builtin features

$computername = $env:COMPUTERNAME
$partition = ‘E:’
$description = ‘backup_server’

Get-WmiObject -Class Win32_LogicalDisk -ComputerName $computername |
select PSComputerName,
@{Name=‘Partition’; Expression={$.DeviceId}},
@{Name=‘Description’; Expression={$description}},
.Size / 1GB), 2)}},
@{Name=‘FreeSpace(GB)’;Expression={[math]::Round(($_.FreeSpace / 1GB), 2)}}

Output an object rather than a string
The computername you can get from the PSComputerName property that is added to all remote WMI results. You can perform the calculations directly in select-object. Use 1GB (powershell understand KB, MB, GB, TB, PB) as the divisor