Last active
October 14, 2018 21:32
-
-
Save dadatuputi/29714b76bbccf99bff34c2c7d23ccc30 to your computer and use it in GitHub Desktop.
Powershell - Unmount VHD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Escalate script if not run as administrator | |
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) | |
{ | |
# Relaunch as an elevated process: | |
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs | |
exit | |
} | |
# Unmount vhd file | |
# Use the following path if the vhd file is in the same directory as this script: | |
# $path = Join-Path $PSScriptRoot my.vhd | |
$path = "C:\path\to\my.vhd" | |
## Hyper-V Method | |
# Use this if you have Hyper-V installed | |
# Dismount-VHD -path $path | |
## Diskpart Method | |
# Use this if you don't want to install Hyper-V | |
$results = @( | |
"select vdisk file=$path", | |
"detach vdisk" | |
) | diskpart | |
# References for Diskpart method: | |
# https://www.top-password.com/blog/mount-and-unmount-vhd-vhdx-from-command-line/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment