Help with function to get local disks

Welcome Forums General PowerShell Q&A Help with function to get local disks

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
4 years, 6 months ago.

  • Author
    Posts
  • #20300

    Participant
    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    I am trying to query computers for local disks and the function that I have works well when querying my local machine, but when I query a server which has a number of local disks I get the following error:

    Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.
    At C:\Users\xxx\Desktop\LocalDisk.ps1:43 char:5
    + $Prop=@{
    + ~~~~~~~~
    + CategoryInfo : InvalidOperation: (op_Division:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

  • #20302

    Participant
    Topics: 8
    Replies: 58
    Points: 0
    Rank: Member

    Problem is at these lines:
    [code]
    'Total Size (GB)' = $Disk.Size / 1gb -as [int]
    'Free Space (GB)' = $Disk.FreeSpace / 1gb -as [int]
    'Free Space (%)' = [double]$Disk.FreeSpace / [double] $_.size * 100 -as [int]
    [/code]

    Values $Disk.Size, $Disk.FreeSpace and $Disk.FreeSpace. Their values cannot be divided, because they contain two numbers.

  • #20304

    Participant
    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    Thanks, that has worked, but I am surprised that it allowed it when I queried my local computer.

    • #20314

      Participant
      Topics: 8
      Replies: 58
      Points: 0
      Rank: Member

      How many fixed disks do you have on your local computer? One?

The topic ‘Help with function to get local disks’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort