首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在没有驱动器盘符的NTFS文件夹中装载的驱动器上使用GET-PSDrive获取信息

如何在没有驱动器盘符的NTFS文件夹中装载的驱动器上使用GET-PSDrive获取信息
EN

Stack Overflow用户
提问于 2021-08-29 17:10:49
回答 1查看 84关注 0票数 1

如何才能获得有关没有驱动器号的驱动器的可用空间和其他信息?这些驱动器是在win 10工作站本地使用磁盘管理控制台安装在NTFS文件夹中的?我需要一个powershell的解决方案,有人能给我一个提示吗?

EN

回答 1

Stack Overflow用户

发布于 2021-08-29 17:46:22

这是一个非常棘手的问题!WMI命名空间Win32_MountPoint包含我们所需的信息,用于查看哪些驱动器被挂载为磁盘驱动器或文件夹。

下面的条目是作为文件夹挂载的驱动器的示例。

代码语言:javascript
运行
复制
#Use Get-WmiObject Win32_MountPoint if the below fails
PS> Get-CimInstance Win32_MountPoint 


Directory             : Win32_Directory (Name = "H:\")
Volume                : Win32_Volume (DeviceID = "\\?\Volume{38569fb2-42e2-4359-8b42-1807...)
PSComputerName        :
CimClass              : root/cimv2:Win32_MountPoint
CimInstanceProperties : {Directory, Volume}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

Directory             : Win32_Directory (Name = "C:\thumb")
Volume                : Win32_Volume (DeviceID = "\\?\Volume{e5d29a99-c6c2-11eb-b472-4ccc...)
PSComputerName        :
CimClass              : root/cimv2:Win32_MountPoint
CimInstanceProperties : {Directory, Volume}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

有了这些信息,mind...we可以将DeviceID信息传递给另一个命令,以找出有多少磁盘空间。

代码语言:javascript
运行
复制
get-volume | ? Path -eq  $mount.Volume.DeviceID

DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus  SizeRemaining    Size
----------- ------------ -------------- --------- ------------ -----------------  -------------    ----
                         FAT32          Removable Warning      Full Repair Needed       3.44 GB 3.74 GB

现在,让我们把它变成一个函数,在这个函数中,您传入挂载路径,然后返回实际磁盘上的信息。

代码语言:javascript
运行
复制
Function Get-MountedFolderInfo{
    param($MountPath)

    $mount = gcim Win32_MountPoint | where directory -like "*$MountPath*"

    if ($null -eq $mount){
        return "no mounted file found at $MountPath"
    }

    $volumeInfo = get-volume | Where-Object Path -eq $mount.Volume.DeviceID
    
    if ($null -eq $VolumeInfo){
        "Could not retrieve info for:"
        return $mount
    }

    $volumeInfo
}
Get-MountedFolderInfo -MountPath C:\thumb

DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus  SizeRemaining    Size
----------- ------------ -------------- --------- ------------ -----------------  -------------    ----
                         FAT32          Removable Warning      Full Repair Needed       3.44 GB 3.74 GB
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68975229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档