Understanding Disk Information PowerShell returns

Welcome Forums General PowerShell Q&A Understanding Disk Information PowerShell returns

Viewing 5 reply threads
  • Author
    Posts
    • #234478
      Participant
      Topics: 1
      Replies: 2
      Points: 18
      Rank: Member

      I am trying to work out what I may be doing wrong but so far, I have not been able to see my mistake (if indeed there is one)

      I have been putting together some scripts to show the layout of a disk at this point just the disk, partition, and volume information. This has been done with PowerShell’s:

      Get-Disk
      Get-PhysicalDisk
      Get-CimInstance ClassName win32_diskdrive

      Using the various bits of information to put together the output shown in the information below.

      What I am finding it difficult to see is with the information returned from the various items above why the arithmetic does not seem to work with the information returned.

      For example:

      Sectors Per Track: [63] * Total Tracks: [2040]
      =
      Total Sectors: [128520]

      But when you look at the partition information:

      MBR:
      Start: [0 (0.00)] End: [512 (512.00)] Size: [512.00]
      Start Sector: [] End Sector: [1]

      Partition 1:
      Offset: [512 (512.00)] End: [65863680] Size: [65863168 (62.81MB)]
      Start Sector: [1] End Sector: [128640]

      The end sector is: 128640
      but the total number of sectors is: 12850

      I can’t see why there is a difference and why when I multiply the numbers together I cannot
      make the figures agree.

      Any insight into what I am missing would be helpful.

      The disk is just a 64MB generic USB stick but the same applies to anything else I have looked at.

      Disk6          : Name: [Generic USB Flash Drive] Serial Number: [] Firmware Version: [%z!Y]
      Partition Style: [MBR] Provisioning Type: [Fixed] Bus Type: [USB]
      Media Type: [Removable Media]
      Size: [65863680 (62.81MB)] Physical Sector Size: [512]
      GUID: [] UniqueID: [{b8caaa6b-1316-d4d8-32e8-ef7dafc9f638}]
      Physical Location: [Integrated : Adapter 0 : Port 0] Media Type: [Unspecified]
      Serial Number: []
      Bytes/Sector: [512] Sectors Per Track: [63] Total Tracks: [2040]
      Tracks/Cylinder: [255] Total Heads: [255] Total Cylinders: [8] Total Sectors: [128520]
      _________________________________________________________________
      MBR            : Start: [0 (0.00)] End: [512 (512.00)] Size: [512.00]
      : Start Sector: [] End Sector: [1]
      _________________________________________________________________
      Part:[1]    : Type: [XINT13] Status: [Online]
      Offset: [512 (512.00)] End: [65863680] Size: [65863168 (62.81MB)]
      Start Sector: [1] End Sector: [128640]
      Access Path(s): [E:\, \\?\Volume{f198a608-aa52-11ea-8987-00019510a995}\]
      __________________________________________________________________________________________________________________
      Vol:[1]  : Drive Letter: [E] FileSystem: [FAT] FileSystem Label: [INITDISK 16] Drive Type: [Removable]
      Health: [Healthy] Status: [OK]
      Size: [62.55MB] Free Space: [62.42MB] Allocation Size: [1024]
      _________________________________________________________________

    • #234544
      Participant
      Topics: 12
      Replies: 1642
      Points: 2,660
      Helping Hand
      Rank: Community Hero

      RayG45, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      Using CIM information is pretty close to the source of data, CIM > Win32 > Get-Disk. Most of the Get-Disk and Get-PhysicalDisk are wrappers for WMI where they are taking the lng value of say DiskType = 3 to show DiskType = ‘Physical’ or whatever the lookup value is so that you don’t have to do it manually, basically pretty human-readable data. There are some values that are derived dynamically via WMI, such as memory consumption in Get-Process is not static and changes with the current consumption. Have not delved into the intricacies of disk statistics or algorithms on how something like Sectors is compiled, but there may be more to their algorithm than value1 + value2 such as bytes per sector or file system used (FAT\NTFS) that is more accurate than a simple value+value. Normally, these questions are for memory or diskspace being different than what is shown in the GUI interface of the OS, but it’s typically because the values are being dynamically generated or the algorithm is taking into account other factors.

    • #234721
      Participant
      Topics: 1
      Replies: 2
      Points: 18
      Rank: Member

      Thanks for the tips.

      So you are saying that the numbers returned do not actually reflect the physical disk data 100%. That makes it difficult to trust what PS is saying. i.e if there are 100 sectors PS might say there are only 90 because it thinks there some other datae formatting is taking up the other 10?

    • #234808
      Participant
      Topics: 5
      Replies: 2372
      Points: 6,005
      Helping Hand
      Rank: Community MVP

      That makes it difficult to trust what PS is saying.

      Why/whatfor would you need these kind of information? Mostly it does not matter for the task we do with Powershell.

    • #234982
      Participant
      Topics: 1
      Replies: 2
      Points: 18
      Rank: Member

      @olaf

      Mostly it does not matter for the task we do with Powershell.

      Thats fine for you if you have no use for that specific information but when you are trying to get the arithmetic to work it makes life difficult and brings into question any other numerical information that you or I might use in the future.

      Just FYI I have also had issues getting the window sizes to work out with top/bottom/left/right, title/scrollbars/borders etc. In the end I had to settle with a compromise that is as near as I am going to get. I was unable to find a page (perhaps you know one) that acuratly describes the layout of a window?

      Having had that in the past I was wondering if it was me or something in PowerShell that I was not allowing for.

      I hope that answers your question – mine however still largly remains unanswered.

       

    • #235012
      Participant
      Topics: 5
      Replies: 2372
      Points: 6,005
      Helping Hand
      Rank: Community MVP

      I hope that answers your question …

      Actually not … you did not say whatfor you need that precise info about partitions, sectors, sectors per track and so on. 😉

      I used to think that Powershell was originally made for administrators and administrative tasks in Windows. So if you want to know how much space you have to save files on a drive you just need the free space of that logical drive. The underlying physics does not matter in this case.

      That’s what I meant. 😉

Viewing 5 reply threads
  • You must be logged in to reply to this topic.