none
Harddisk infromation RRS feed

  • Question

  • I need to get the following information about a Harddisk :_

    1. UsedSpace

    2. The Disktype (Basic or Dynamic)

    I am using powershell 2.0 version, and just not getting the above informations.

    It appears that the "win32_diskdrive" doesn't have these two parameters. How can i get the "UseDSpace and DiskType" ? ?

    Wednesday, March 25, 2015 12:44 PM

Answers

  • Don't try to be so fancy.  It is causing things to not work as expected.

    $Servers =  "k0z0", "k0z0s!"
    Foreach ($Srvr in $Servers){
       Invoke-Command -ScriptBlock {'list disk' | diskpart} -ComputerName $srvr
    }  

    THe second computername is actually an illegal name.


    ¯\_(ツ)_/¯

    • Marked as answer by Koz0s Monday, March 30, 2015 6:49 AM
    Thursday, March 26, 2015 11:26 AM

All replies

  • Use win32_logicaldisk to get used space.
    Wednesday, March 25, 2015 12:56 PM
  • I need the UsedSpace of the Harddisk not the logical drives. 

    Let's say the harddisk has 350 GB so need to know how much space is allocated and how much space is unallocated?

    Wednesday, March 25, 2015 1:26 PM
  • It will get you both. If you run this you will see the C drive is listed - 

    gwmi -query "select * from win32_logicaldisk" | Select DeviceId,@{N="Size";E={$_.size/1gb}}, @{N="Free";E={$_.Freespace/1gb}}

    Wednesday, March 25, 2015 1:33 PM
  • Have a look at the following article:

    http://stackoverflow.com/questions/12159341/powershell-how-to-get-disk-capacity-and-free-space-of-remote-computer

    From there you could use the following:

    gwmi Win32_LogicalDisk -ComputerName remotecomputer -Filter "DriveType=3" | select Name, FileSystem,FreeSpace,BlockSize,Size | % {$_.BlockSize=(($_.FreeSpace)/($_.Size))*100;$_.FreeSpace=($_.FreeSpace/1GB);$_.Size=($_.Size/1GB);$_} | Format-Table Name, @{n='FS';e={$_.FileSystem}},@{n='Free, Gb';e={'{0:N2}'-f $_.FreeSpace}}, @{n='Free,%';e={'{0:N2}'-f $_.BlockSize}},@{n='Capacity ,Gb';e={'{0:N3}' -f $_.Size}} -AutoSize

    Where remote computer is the name of the computer you want to query.

    Wednesday, March 25, 2015 1:47 PM
  • None of the above commands give me the UsedSpace of the Disk.

    I am trying the folllowing code, and the script is pulling only the same server information.

    $Servers =  "k0z0", "k0z0s!"
    $commands = @"
    list disk
    "@
    Foreach ($Srvr in $Servers)
    {
       $s = New-PSSession -computername $Srvr
       Enter-PSSession -session $s
       $commands | diskpart
       Exit-PSSession
    }    
    

    Microsoft DiskPart version 6.1.7601
    Copyright (C) 1999-2008 Microsoft Corporation.
    On computer: K0z0

    DISKPART> 
      Disk ###  Status         Size     Free     Dyn  Gpt
      --------  -------------  -------  -------  ---  ---
      Disk 0    Online           25 GB      0 B         
      Disk 1    Online           10 GB  1024 KB         

    DISKPART> 

    Microsoft DiskPart version 6.1.7601
    Copyright (C) 1999-2008 Microsoft Corporation.
    On computer: K0z0

    DISKPART> 
      Disk ###  Status         Size     Free     Dyn  Gpt
      --------  -------------  -------  -------  ---  ---
      Disk 0    Online           35 GB      0 B         
      Disk 1    Online           10 GB  1024 KB        

    Thursday, March 26, 2015 9:16 AM
  • Just subtract the free space from the total space and it will get you how much space is being used - 

    gwmi -query "select * from win32_logicaldisk" | Select DeviceId,@{N="Size";E={$_.size/1gb}}, @{N="Free";E={$_.Freespace/1gb}}, @{N="Used";E={($_.Size - $_.freespace)/1gb}}


    • Edited by Braham20 Thursday, March 26, 2015 9:19 AM
    Thursday, March 26, 2015 9:18 AM
  • I don't need the space of logical disks.. I need the space of the harddisk.. i.e. how much space of a harddisk is allocated and how much it is not ?

    lets say I have 350GB harddisk

    I allocate 50 - C, 60- D, and have 240 as unallocated space. So how do I get this information.  SInce I have PowerShell 2.0, I am unable to use Get-Disk command.


    • Edited by Koz0s Thursday, March 26, 2015 9:58 AM
    Thursday, March 26, 2015 9:57 AM
  • Hmmm, I've been trawling WMI and I can't find any clear way to link partitions back to a physical disk. I suspect it will be difficult although I may have missed something quite obvious. Hopefully somebody else can help you.
    Thursday, March 26, 2015 11:25 AM
  • Don't try to be so fancy.  It is causing things to not work as expected.

    $Servers =  "k0z0", "k0z0s!"
    Foreach ($Srvr in $Servers){
       Invoke-Command -ScriptBlock {'list disk' | diskpart} -ComputerName $srvr
    }  

    THe second computername is actually an illegal name.


    ¯\_(ツ)_/¯

    • Marked as answer by Koz0s Monday, March 30, 2015 6:49 AM
    Thursday, March 26, 2015 11:26 AM
  • Would this not work as well?

    Get-WmiObject Win32_Volume -ComputerName localhost | Select Name, Capacity, FreeSpace, FileSystem | Format-Table Name, @{n='FS';e={$_.FileSystem}},@{n='Free, Gb';e={'{0:N2}' -f ($_.FreeSpace/1gb)}}, @{n='Capacity ,Gb';e={'{0:N2}' -f ($_.Capacity/1GB)}} -AutoSize

    Thursday, March 26, 2015 12:26 PM
  • Thank you... this worked. Now just need to figure out how to save the output in the hash table . :)


    • Edited by Koz0s Thursday, March 26, 2015 1:22 PM
    Thursday, March 26, 2015 1:19 PM