#Diskpart挂载VHD

$DriveLetter = "X"
$VHD_File = "e:\vhd\test\win2008r2.vhdx"
$CurrentPath = "e:\vhd"


Function Diskpart_Mount ($DriveLetter,$VHD_File)
{
$now = get-date -format 'yyyyMMddHHmm'
$dpmountcmd_ScriptName = "DPMount_script_" + $now + ".txt"
$dpmountcmd_ScriptPath = Join-Path -Path $CurrentPath -ChildPath $dpmountcmd_ScriptName
$dpmountcmd = @()
$dpmountcmd += ("Select Vdisk file" + " = """ + $VHD_File + """")
$dpmountcmd += ("Attach Vdisk")
$dpmountcmd += ("Select Partition 2")
$dpmountcmd += ("Assign letter=" + $DriveLetter)
$dpmountcmd += ("Exit")
Set-Content -Path $dpmountcmd_ScriptPath -Value $dpmountcmd
Diskpart -s $dpmountcmd_ScriptPath
}

Diskpart_Mount $DriveLetter $VHD_File

 

 

=================================================

 

#Diskpart卸载VHD

$DriveLetter = "X"
$VHD_File = "e:\vhd\test\win2008r2.vhdx"
$CurrentPath = "e:\vhd"


Function Diskpart_Unmount ($VHD_File)
{
$now = get-date -format 'yyyyMMddHHmm'
$dpunmountcmd_ScriptName = "DPUnmount_script_" + $now + ".txt"
$dpunmountcmd_ScriptPath = Join-Path -Path $CurrentPath -ChildPath $dpunmountcmd_ScriptName
$dpunmountcmd = @()
$dpunmountcmd += ("Select Vdisk file" + " = """ + $VHD_File + """")
$dpunmountcmd += ("Detach Vdisk")
$dpunmountcmd += ("Exit")
Set-Content -Path $dpunmountcmd_ScriptPath -Value $dpunmountcmd
Diskpart -s $dpunmountcmd_ScriptPath
}

Diskpart_Unmount $VHD_File

相关文章:

  • 2021-06-07
  • 2022-01-08
  • 2021-08-27
  • 2021-07-30
  • 2021-07-28
  • 2021-07-17
  • 2021-08-12
  • 2022-12-23
猜你喜欢
  • 2021-05-12
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案