windows server更改盘符
使用powershell更改盘符
echo `n
Write-host "Display existing driveLetter partition" -ForegroundColor Green
Get-Volume
echo `n
function getvolume
{
$volume_a = Get-Volume | Select-Object -Property DriveLetter,DriveType
$hashTablea = @{}
foreach($volumeInfoa in $volume_a)
{
if ($volumeInfoa.DriveType -eq "Removable" -or $volumeInfoa.DriveType -eq "CD-ROM")
{
$hashTablea.Add($volumeInfoa.DriveType,$volumeInfoa.DriveLetter)
}
}
$hashTablea."CD-ROM"
$hashTablea."Removable"
}
$cdname, $medianame = getvolume
$volumeInfos=Get-WmiObject -Class win32_volume
$hashTable = @{}
$nu = $null
foreach($volumeInfo in $volumeInfos)
{
if ( $volumeInfo.DriveType -eq 2 )
{
$mdl = $volumeInfo.DriveLetter
$mdl = $mdl.Split(":")[0]
$medianum = $volumeInfo.DriveType
if ( $mdl -eq $medianame )
{
Write-host "Modify CD-ROM drive letter to F" -ForegroundColor Green
Get-WmiObject -Class win32_volume -Filter "drivetype=$medianum" | Select-Object -First 1 | Set-WmiInstance -Arguments @{DriveLetter='G:'}
}
}
echo `n
if ( $volumeInfo.DriveType -eq 5 )
{
$cdl = $volumeInfo.DriveLetter
$cdl = $cdl.Split(":")[0]
$cdnum = $volumeInfo.DriveType
if ( $cdl -eq $cdname )
{
Write-host "Modify the Removable drive letter to G" -ForegroundColor Green
Get-WmiObject -Class win32_volume -Filter "drivetype=$cdnum" | Select-Object -First 1 | Set-WmiInstance -Arguments @{DriveLetter='H:'}
}
}
}
echo `n
Write-host "Display the changed drive letter" -ForegroundColor Green
Get-Volume
echo `n
sleep 10