Disk size and Free space in GB using Power shell

srinath sarman 41 Reputation points
2020-11-02T08:14:45.627+00:00

Hello,

I tried below command to get the disk size and free space.

Get-WmiObject -Class Win32_LogicalDisk -ComputerName <Server_Name> | ? {$_. DriveType -eq 3} | select DeviceID,Size,FreeSpace

Below one is the out and i wanted to convert it to GB and tried save the command out put to variable $ds and performed $dsgb = ((($ds.size/1024)/1024)/1024 unfortunately its throwing error

DeviceID Size FreeSpace


C: 128741040128 62821122048
D: 68717375488 62158524416

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,553 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Laude 85,816 Reputation points
    2020-11-02T08:24:47.997+00:00

    Hi @srinath sarman ,

    Try the following:

    Get-WmiObject -Class Win32_LogicalDisk -ComputerName <Server_Name> | ? {$_. DriveType -eq 3} | select DeviceID, {$_.Size /1GB}, {$_.FreeSpace /1GB}  
    

    ----------

    (If the reply was helpful please don't forget to upvote or accept as answer, thank you)

    Best regards,
    Leon

    5 people found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Nav Shah 25 Reputation points
    2023-01-11T10:37:47.5533333+00:00

    Updated script to round off without decimal and use LocalHost as Computername

    Get-WmiObject -Class Win32_LogicalDisk -ComputerName LOCALHOST | ? {$_. DriveType -eq 3} | select DeviceID, {[int]($_.Size /1GB)}, {[int]($_.FreeSpace /1GB)}
    

    User's image

    User's image

    5 people found this answer helpful.
    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.