Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a working program that retrieves information of disk such as FreeSpace, TotalSpace etc from a remote server. I have a problem however that i cannot get these stattistics for all Clustered Disks mapped on onto the server. Th query only returns information for the Local Disk (Logical Disk).

I am able to get disk space sizes as below :

C#
<pre>public List<Disk> GetEnvironmentStatistics()
        {
            var serverIP = Convert.ToString(System.Web.HttpContext.Current.Session["ServerIP"]); 
         
            List<Disk> diskinfo = new List<Disk>();

            //Add System.Management to access these utilities
            ConnectionOptions options = new ConnectionOptions
            {

                Username = Convert.ToString(System.Web.HttpContext.Current.Session["Username"]),
                Password = Convert.ToString(System.Web.HttpContext.Current.Session["Password"]),
                Authority = Convert.ToString(System.Web.HttpContext.Current.Session["Authority"]),
            };

            //root - root of the tree, cimv2 - version           
            ManagementScope scope = new ManagementScope("\\\\" + serverIP + "\\root\\CIMV2", options);
            scope.Connect();

            SelectQuery query = new SelectQuery("Select * from Win32_LogicalDisk");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection queryCollection = searcher.Get();

           
                foreach (ManagementObject mo in queryCollection)
                {
                    Disk disk = new Disk();
                    disk.DiskName = mo["Name"].ToString();                  
                    disk.DeviceId = mo["DeviceID"].ToString();
                    disk.SystemName = mo["SystemName"].ToString();

                    disk.FreeSpace = Convert.ToDecimal(mo["FreeSpace"]);
                    var formattedFreeSpace = Helpers.DiskSpaceInGigabytes(disk.FreeSpace ?? 0);
                    disk.FreeSpace = Decimal.Truncate(formattedFreeSpace);
                
                    disk.TotalSpace = Convert.ToDecimal(mo["Size"]);
                    var formattedTotalSpace = Helpers.DiskSpaceInGigabytes(disk.TotalSpace ?? 0);
                    disk.TotalSpace = Decimal.Truncate(formattedTotalSpace);
                   
                    disk.UsedSpace = disk.TotalSpace - disk.FreeSpace;
                    
                    var HDPercentageUsed = 100 - (100 * disk.FreeSpace / disk.TotalSpace);
                    disk.PercentageUsed = Convert.ToInt32(HDPercentageUsed);
                    diskinfo.Add(disk);
                }

              
                   
            return diskinfo;
        }


I have logged into the server and noted the other disks appear as Clustered Disk
.

What I have tried:

How do i get information about the space on the Clustered Disks using WMI. Is there a way to specify the type of Drive in WMI , in this case specifying that its a Clustered Disk and not Local Disk.. i would like to think if i can specify the drive type then i should also be able to get information for the Clustered Disks.

I have been looking at this https://www.avianwaves.com/Blog/ArticleID/178/PowerShell-WMI-Free-Disk-Space-from-a-Cluster-Shared-Volume-CSV-in-a-Windows-Failover-Cluster but it doesnt quite suit my requirements and its Powershell also .
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900