Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'

Executing the following code , I am getting the error.Please let me where I doing mistake

Code

$diskDetails = Get-WMIObject -Namespace root/cimv2 -Class Win32_LogicalDisk | Where-Object {$_.DeviceID -match “$($Arguments)” } | Select-Object -Property Size, FreeSpace, VolumeName, DeviceID
$DriveLetter = $diskDetails.DeviceID
$DriveName = $diskDetails.VolumeName
$SizeInGB = “{0:0}” -f ($diskDetails.Size/1GB)

Error

Method invocation failed because [System.Object[]] does not contain a method
named ‘op_Division’.
At line:4 char:1
+ $SizeInGB = “{0:0}” -f ($diskDetails.Size/1GB)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Division:String) [], Runtim
eException
+ FullyQualifiedErrorId : MethodNotFound

From my feeling I would say the content of $Arguments is not like you expect. I assume there are some blanks or an array is in there. I would check this first.

Please try:

$Arguments.GetType()
$Arguments[0]
$Arguments[1]
write-host ">$Arguments<"

What do you get back for these three lines?

 

I tried to use ‘C:’ as value for $Arguments and your code works.

Alternatively you could add a second step:

$tmpSize = $diskDetails.Size -as [double]
$SizeInGB = “{0:0}” -f ($tmpSize/1GB)
1 Like