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 :
<pre>public List<Disk> GetEnvironmentStatistics()
{
var serverIP = Convert.ToString(System.Web.HttpContext.Current.Session["ServerIP"]);
List<Disk> diskinfo = new List<Disk>();
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"]),
};
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 .