Powershell代码,用于自动删除驱动器号

时间:2016-09-14 00:51:14

标签: windows powershell automation

有人可以帮我解决如何使用PowerShell从内存最少的驱动器中删除驱动器号的方法吗?
我有一个7 MB的分区,我想删除它的驱动器号....

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

获得最小的音量:

# 'Fixed' type avoids choosing a CD-ROM drive with no media in it, at 0 bytes

$Volumes = Get-Volume | Where-Object DriveType -eq 'Fixed' 
$SmallestVolume = $Volumes | Sort-Object -Property Size | select -First 1

然后深入阅读Scripting Guy博客,了解如何删除驱动器号,找到建议的方法不起作用,然后使用注释找到有效的方法:

$SmallestVolume | Get-Partition | ForEach { 
    Remove-PartitionAccessPath -DiskNumber $_.DiskNumber -PartitionNumber $_.PartitionNumber -AccessPath "$($_.DriveLetter):"
}

我试过一次,YMMV。需要以'管理员或Get-Partition将没有结果。