Reputation: 31
Can someone help me out with a way on how to remove a drive letter from the drive with the least memory using powershell ?
I have a partition that is 7 mb and i want to remove the drive letter from it....
any help will be greatly appreciated
Upvotes: 0
Views: 2133
Reputation: 28983
Get the smallest volume:
# '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
Then dig through the Scripting Guy blog to find out how to remove a drive letter, find the suggested method doesn't work, then use the comments to find a method which does work:
$SmallestVolume | Get-Partition | ForEach {
Remove-PartitionAccessPath -DiskNumber $_.DiskNumber -PartitionNumber $_.PartitionNumber -AccessPath "$($_.DriveLetter):"
}
I tried it once, YMMV. Needs to be 'run as' administrator, or Get-Partition
will have no results.
Upvotes: 2