zoukankan      html  css  js  c++  java
  • Diskpart挂载/卸载VHD

    #Diskpart挂载VHD

    $DriveLetter = "X"
    $VHD_File = "e:vhd estwin2008r2.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 estwin2008r2.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

  • 相关阅读:
    关于MFC库和CRT库冲突的分析
    C++ Traits技术
    C/C++的参数传递机制
    C++与正态分布
    前端JavaScript
    python 前端 css
    python 前端 html
    MySQL 数据库
    网络编程 生产者消费者模型 GiL

  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/3452683.html
Copyright © 2011-2022 走看看