[英]Is there a way to get the free space on an iSCSI drive mounted as a NTFS folder
I have a bunch of iSCSI drives mounted as NFTS folders (to avoid exhausting all the drive letters) acting as a mini SAN, and I would like to get the information about their free space. 我有一堆作为NFSAN文件夹安装的iSCSI驱动器( 作为NFTS文件夹 ,以避免耗尽所有驱动器号),我想获得有关其可用空间的信息。 The basic reason is to get warnings when space gets below a certain threshold, as a part of a scheduled task which does a bunch of other checks.
根本原因是当空间低于特定阈值时发出警告,这是计划任务的一部分,该任务还会执行其他一系列检查。
Is there a way to do it, preferably using C# (through WMI, P/Invoke, or whatever)? 有没有办法做到这一点,最好使用C#(通过WMI,P / Invoke或其他方法)? Of course, any scripting solution would also be great, as I can probably invoke it anyway (PowerShell)?
当然,任何脚本解决方案也都很棒,因为无论如何我都可以调用它(PowerShell)? I tried the optimistic route first, using
DriveInfo
initialized with using such a path, but it simply returns information about the root volume instead of the mount. 我首先尝试了乐观路线,使用的
DriveInfo
使用此类路径进行了初始化,但它只是返回有关根卷而不是装载的信息。 I've also tried enumerating stuff like Win32_DiskPartition
, Win32_LogicalDisk
and Win32_MappedLogicalDisk
but didn't get those drives at all. 我还尝试枚举
Win32_DiskPartition
, Win32_LogicalDisk
和Win32_MappedLogicalDisk
类的东西,但根本没有得到这些驱动器。
As @FrédéricHamidi explained, Win32_Volume class in the WMI Storage Volume Provider shows correct space information about mounted volumes. 正如@FrédéricHamidi解释的那样,WMI存储卷提供程序中的Win32_Volume类显示有关已安装卷的正确空间信息。
Usage example (C#) would be something like: 使用示例(C#)类似于:
// iSCSI drive mounted in a NTFS folder
var ntfsPath = @"x:\iscsi\volume";
// it's good to know that backspaces must be escaped in WMI queries
var cmd = string.Format(
"SELECT * FROM Win32_Volume WHERE Name LIKE '{0}%'",
ntfsPath.Replace(@"\", @"\\"));
using (var searcher = new ManagementObjectSearcher(cmd))
{
foreach (ManagementObject queryObj in searcher.Get())
{
var name = (string)queryObj["Name"];
var freeSpaceInBytes = (ulong)queryObj["FreeSpace"];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.