0

The value of size that wmic logicaldisk get size returns is basically the advertised size of the hard drive. However, I am trying to obtain the total disk size minus the reserved space.

Since I could not figure out how to retrieve this value from diskpart list disk without launching an actual instance of command prompt, I am now trying to obtain it from PowerShell with the code below.

cp.exec('get-volume', {'shell': 'powershell.exe'}, (error, stdout)=>{
  console.log(stdout)
})

DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining      Size
----------- ------------ -------------- --------- ------------ ----------------- -------------      ----
D           [removed]    NTFS           Fixed     Healthy      OK                    930.74 GB 930.91 GB
C           System       NTFS           Fixed     Healthy      OK                    520.67 GB 930.88 GB
                         NTFS           Fixed     Healthy      OK                    112.01 MB    450 MB
            Recovery     NTFS           Fixed     Healthy      OK                    109.23 MB    529 MB
            Recovery     NTFS           Fixed     Healthy      OK                     73.03 MB    499 MB

The problem is that when the PowerShell query is narrowed to get-volume | format-list size, it reverts to returning the advertised size of the disk.

size : 999558213632 // basically 1TB instead of 930 GB

Why does it revert back to the advertised size?

Does anybody know how I can obtain the practical size of the disk (i.e. 930 GB)?

oldboy
  • 5,729
  • 6
  • 38
  • 86
  • 1
    Take a look at this post because your question seem to be more related to ps than to nodejs https://stackoverflow.com/q/12159341/10707187 – midugh Jan 01 '20 at 04:45
  • 1
    @R.LM that is actually the one im already looking at lol. i found one string that worked: `Get-CimInstance win32_logicaldisk | where caption -eq "D:" | foreach-object {write "$($_.Size/1gb)"}` – oldboy Jan 01 '20 at 04:49
  • @R.LM for some reason if you type `1mb` into PowerShell, the value it returns is `1048576` instead of `1000000`. im dumbfounded – oldboy Jan 01 '20 at 04:55
  • 1
    Lovely windows lol – midugh Jan 01 '20 at 04:56
  • @R.LM lol and of course the values for `1gb`, `1tb`, etc are all wonky too. no wonder all of this has been so goddamn confusing :/ – oldboy Jan 01 '20 at 04:57
  • Actually Powershell calculates that correct ... take a look at this: [Byte](https://en.wikipedia.org/wiki/Byte) ... and pay attention to the unit multiples! – Olaf Jan 01 '20 at 05:04
  • @Olaf wow youre right. its because Windows is of course binary. does Linux also calculate it in a binary base? – oldboy Jan 01 '20 at 05:38
  • @R.LM [check this out](https://superuser.com/questions/1513829/wonky-size-units-in-powershell-windows/1513830#1513830) does linux or unix calculate it differently than windows? – oldboy Jan 01 '20 at 05:39
  • Thanks about that @oldboy, i didn’t know about that – midugh Jan 01 '20 at 05:49
  • @Olaf so is 1TB equal to 1024GBs in a binary system? lastly, why are the unit sizes called the same things in diff base number systems? is 1TB in binary considered equal to 1TB in decimal? – oldboy Jan 01 '20 at 05:59
  • @R.LM np! are you on linux or unix? if so, do they treat numbers in the binary or decimal system? – oldboy Jan 01 '20 at 05:59
  • As far as i know both unix and windows uses binary systems. They are based on bytes (2^3) and everything is treated as binary (ascii is 128 characters which is 2^7 and so on) but when it comes to the way the bash command has been developed i don’t know really much. – midugh Jan 01 '20 at 06:04
  • @R.LM super interesting. yeah its weird cuz i know computers r based on binary, and id always see numbers like 128, 1024, etc, but it never clicked that thats because it is all based on binary if that makes any sense. do u know if 1TB in decimal is considered equal to 1TB in binary or am i thinking about this wrongly? – oldboy Jan 01 '20 at 06:06
  • 1 *tera*byte is (canonically) *always* 1000 *giga*bytes = 1 000 000 *mega*bytes = 1 000 000 000 *kilo*bytes = 1 000 000 000 bytes. There is a different measure for base-2 sizes: 1 *tebi*byte (TiB) = 1024 *gibi*bytes (GiB) = 1 048 576 *mebi*bytes (MiB) = 1 073 741 824 *kibi*bytes (KiB) = 1 099 511 627 776 bytes. Windowsis simply lying to you when it says KB, MB, GB, TB but means KiB, MiB, GiB, TiB. Check [Wikipedia on binary prefixes and inconsistencies](https://en.wikipedia.org/wiki/Binary_prefix#Inconsistent_use_of_units) – VLAZ Jan 01 '20 at 10:35
  • 3
    **Voted to close.** The question in the title differs from the question at the bottom of the content, nevertheless both questions (including the discussion [1024 vs 1000](https://devblogs.microsoft.com/powershell/kb-1024-vs-1000/)) can be found in many other questions (search for e.g. [`PowerShell GB`](https://stackoverflow.com/search?q=powershell+gb)) and the common solution for [**Does anybody know how I can obtain the practical size of the disk (i.e. 930 GB)?**](https://stackoverflow.com/a/57535324/1701026). – iRon Jan 01 '20 at 10:42
  • @iRon since when did SO turn into merely a forum to discuss programming concepts? i thought SO was about asking questions about stuff you dont know to learn about the stuff you dont know... – oldboy Jan 02 '20 at 00:21
  • The reason that I voted to close has nothing to do with either a programming concept or asking questions but because the possible answers were already supplied in several similar questions. If still think your question isn't answered anywere else, I recommend to create a new question and possible refer to similar questions and were they don't specifically answer yours. – iRon Jan 03 '20 at 14:34
  • @iRon the initial reason was that the title of the question and the question asked at the end were different... – oldboy Jan 03 '20 at 20:21

0 Answers0