Last active
July 4, 2024 02:09
-
-
Save willsantos/e4989992d31d9092d79c3f0ff9a240cd to your computer and use it in GitHub Desktop.
Mount 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
param([switch]$Elevated) | |
function Test-Admin { | |
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) | |
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
} | |
if ((Test-Admin) -eq $false) { | |
if ($elevated) | |
{ | |
# tried to elevate, did not work, aborting | |
} | |
else { | |
Start-Process pwsh.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) | |
} | |
exit | |
} | |
'running with full privileges' | |
$ErrorActionPreference = "Stop" | |
Write-Output "Montando VHD...." | |
$disk_number = (Mount-VHD -Path .\projects.vhdx -PassThru | Get-Disk).Number | |
Write-Output "VHD montada com sucesso" | |
Write-Output "Montando disco no WSL" | |
wsl --mount \\.\PHYSICALDRIVE$disk_number | |
Write-Output "Disco montado no WSL" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment