PowerShell Script for show Virtual Machine Drive details like DiskName, DriveLetter, Size and FileSystem

Dnyaneshwar Surywanshi 156 Reputation points
2021-01-27T14:38:06.087+00:00

I want to show the VM Machine Drive details using powershell script so if anyone have please share with me or give me any reference.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,123 questions
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,362 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Monalla-MSFT 11,636 Reputation points
    2021-01-27T23:43:57.64+00:00

    @Dnyaneshwar Surywanshi - Thanks for reaching out.

    If your VM runs in Azure, Get-AzDisk would retrieve information about the underlying disk.

    Here is the doc info for that- Get-AzDisk PowerShell Script

    If the above response was helpful, please feel free to "Accept as Answer" , so it can be beneficial to the community.


  2. Dnyaneshwar Surywanshi 156 Reputation points
    2021-01-28T11:13:38.347+00:00

    @Monalla-MSFT Below is my script to get Drive details of azure VM so I want to run this from my Local server machine .

    Get-WmiObject Win32_DiskDrive | ForEach-Object {
    $disk = $_
    $partitions = "ASSOCIATORS OF " +
    "{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
    "WHERE AssocClass = Win32_DiskDriveToDiskPartition"
    Get-WmiObject -Query $partitions | ForEach-Object {
    $partition = $_
    $drives = "ASSOCIATORS OF " +
    "{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
    "WHERE AssocClass = Win32_LogicalDiskToPartition"
    Get-WmiObject -Query $drives | ForEach-Object {
    New-Object -Type PSCustomObject -Property @{
    DriveLetter = $.DeviceID
    VolumeName = $
    .VolumeName
    Size = '{0:d} GB' -f int
    FreeSpace = '{0:d} GB' -f int
    }
    }
    }
    }

    Please let me know any idea or information about how i can get from loacal.

    0 comments No comments

  3. Monalla-MSFT 11,636 Reputation points
    2021-01-28T15:29:13.467+00:00

    @Dnyaneshwar Surywanshi - Thanks for providing more details.

    If you would like to run this from your local server Machine and If you are using a modern Windows system then you could try the below commands :

    Get-PhysicalDisk,

    Get-Disk

    Get-Partition

    depending on the specific properties you are looking for. WMI is the older way of doing it, but it's more compatible with older systems and still works with modern ones.

    Drive letters are associated with partitions, not physical disks so you can try using Get-Partition for that.

    If you're looking for properties associated with the physical disk, you can try using Get-PhysicalDisk for that.

    Please feel free to "Accept as Answer" if the response was helpful.