windows查看分区信息
#列出所有正在使用的驱动器号
$useddrives = @( )
Get-PSDrive -PSProvider FileSystem | ForEach-Object { $useddrives += $_.Name }
#列出所有还可以使用的驱动器号
$availabledrives = @( )
[int][char]"A"..[int][char]"Z" | ForEach-Object {
[string]$drive = [string][char][int]$_
if ( -not ( $useddrives.Contains( "$drive" ) ) ) {
$availabledrives += $drive
}
}
# 显示正在使用的驱动器号列表
if ( $Used -or -not $Available ) {
if ( $V -or -not ( $Available -xor $Used ) ) {
Write-Host "Drive Letters In Use: " -NoNewline
}
$useddrives | ForEach-Object { Write-Host " $_" -NoNewline; Write-Host ":" -NoNewline }
Write-Host
}
#显示可用驱动器号列表
if ( $Available -or -not $Used ) {
if ( $V -or -not ( $Available -xor $Used ) ) {
Write-Host "Available Drive Letters:" -NoNewline
}
$availabledrives | ForEach-Object { Write-Host " $_" -NoNewline; Write-Host ":" -NoNewline }
Write-Host
}
日期:2020-04-11 23:04:33 来源:oir作者:oir
