You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows PowerShell中通过磁盘序列号查询对应盘符

PowerShell通过序列号查询对应盘符实现方案

功能说明

支持两种序列号查询场景:卷序列号查询、物理磁盘序列号查询,你原有代码存在管道符缺失、关联逻辑混乱的问题,修正后的可运行代码如下:


场景1:通过卷序列号查询盘符

适用于你已知磁盘分区的卷序列号的场景,替换代码中的目标序列号即可直接运行:

# 替换为你需要查询的实际卷序列号
$targetVolumeSerial = "66B78EE4"

Get-CimInstance -ClassName Win32_LogicalDisk | 
Where-Object { $_.VolumeSerialNumber -eq $targetVolumeSerial } | 
Select-Object -ExpandProperty DeviceID

运行后直接返回对应盘符,格式为C:、D:这类。


场景2:通过物理磁盘序列号查询盘符

适用于你已知硬盘本身的物理序列号的场景,替换代码中的目标序列号即可直接运行:

# 替换为你需要查询的实际物理磁盘序列号
$targetDiskSerial = "替换为你的物理磁盘序列号"

Get-CimInstance Win32_DiskDrive | 
Where-Object { $_.SerialNumber.Trim() -eq $targetDiskSerial } |
Get-CimAssociatedInstance -Association Win32_DiskDriveToDiskPartition |
Get-CimAssociatedInstance -Association Win32_LogicalDiskToPartition |
Select-Object -ExpandProperty DeviceID

如果需要同时查看盘符对应的更多属性,可以把最后一行的-ExpandProperty DeviceID修改为Select-Object DeviceID, VolumeName, Size, VolumeSerialNumber。


内容的提问来源于stack exchange,提问作者Suganthan Raj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 00:36:07