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

  • 相关阅读:
    [leetcode]Longest Common Prefix
    [leetcode]Container With Most Water
    [leetcode]Regular Expression Matching
    [leetcode]Palindrome Number
    [leetcode]String to Integer (atoi)
    [leetcode]Reverse Integer
    [leetcode]ZigZag Conversion
    [leetcode]Longest Palindromic Substring
    [leetcode]Add Two Numbers
    poj 1228 Grandpa's Estate
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/3452683.html
Copyright © 2011-2022 走看看