Share via


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

Question

Wednesday, October 10, 2018 6:00 PM

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

All replies (4)

Wednesday, October 10, 2018 6:23 PM | 1 vote

You can't both pipe and create a result variable.

Start with this:

$deviceID = 'C:'
Get-WMIObject Win32_LogicalDisk -Filter "DeviceId='$deviceID'" |
    Select-Object Size, FreeSpace, VolumeName, DeviceID, @{n='Size(Gb)';e={[int]($_.Size/1GB)}}

\(ツ)_/


Wednesday, October 10, 2018 8:00 PM

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

Like the error says, $diskdetails.size is an array of multiple objects.  "$diskDetails.Size/1GB" is an attempt to divide an array by a number.  You may want to use a foreach loop.  Unless you want to define a custom division method for object arrays!


Friday, October 26, 2018 9:05 AM

Hi,

Was your issue resolved?

If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

Best Regards,

Lee

Just do it.


Monday, November 5, 2018 9:43 AM

Hi,

As this thread has been quiet for a while, we will mark it as ‘Answered’ as the information provided should be helpful. If you need further help, please feel free to reply this post directly so we will be notified to follow it up. You can also choose to unmark the answer as you wish.

Best Regards,

Lee

Just do it.