给定一个PowerShell磁盘,我怎么知道它是否可移动?

时间:2018-07-21 21:58:10

标签: powershell disk

在这样的代码下,如果磁盘是固定的或可移动的,是否有任何cmdlet方法可以获取?

$disk = Get-Disk -Number 1
Get-DiskDriveType $disk

Get-DiskDriveType应该返回RemovableFixed的地方。

1 个答案:

答案 0 :(得分:3)

  

使用PowerShell的库存驱动器类型

     

https://blogs.technet.microsoft.com/heyscriptingguy/2014/09/10/inventory-drive-types-by-using-powershell

两种方法:

Get-Volume

DriveLetter FileSystemLabel FileSystem  DriveType  HealthStatus SizeRemaining Size
----------- ----------- ----------  ---------  ---------- ----------       ----

C           SSD         NTFS        Fixed      Healthy      75.38 GB  148.53 GB
E           HybridTe... NTFS        Fixed      Healthy     560.71 GB  931.39 GB
D           FourTB_B... NTFS        Fixed      Healthy        1.5 TB    3.64 TB
F           TwoTB_BU... NTFS        Fixed      Healthy     204.34 GB    1.82 TB
G           USB3        NTFS        Removable  Healthy       6.73 GB   58.89 GB
            Recovery    NTFS        Fixed      Healthy      22.96 MB     300 MB
H                                   CD-ROM     Healthy           0 B        0 B

$hash = @{
    2 = "Removable disk"
    3 = "Fixed local disk"
    4 = "Network disk"
    5 = "Compact disk"
}

Get-CimInstance Win32_LogicalDisk |
Select DeviceID, VolumeName,
@{LABEL='TypeDrive';EXPRESSION={$hash.item([int]$_.DriveType)}}