Com a ajuda de um thread de technet, Eu finalmente fiz meus scripts funcionarem:
Os scripts finais de trabalho são estes:
Mount.ps1:
$scriptDir = Split-Path($MyInvocation.MyCommand.Definition)
$vhdPath = Join-Path $scriptDir "\_private\crypted.vhdx"
$mountPath = Join-Path $scriptDir "\Data"
if(-not (Get-ChildItem $mountPath -ea SilentlyContinue)) # check if not already mounted
{
$diskPartScriptContent = @(
"select vdisk file=$vhdPath",
"attach vdisk"
)
$diskPartScriptFile = Join-Path $scriptDir "_diskpart.tmp"
Set-Content -Path $diskPartScriptFile -Value $diskPartScriptContent
$result = (& diskpart.exe /s $diskPartScriptFile)
& mountvol n:\data "\?\Volume{820c8453-f504-11e2-bedd-9e2cd2a4b688}"
}
else{
Write-Warning "Already mounted"
}
Desmontar.ps1:
$scriptDir = Split-Path($MyInvocation.MyCommand.Definition)
$vhdPath = Join-Path $scriptDir "\_private\crypted.vhdx"
$mountPath = Join-Path $scriptDir "\Data"
if(Get-ChildItem $mountPath -ea SilentlyContinue) # check if not already mounted
{
$diskPartScriptContent = @(
"select vdisk file=$vhdPath",
"detach vdisk"
)
$diskPartScriptFile = Join-Path $scriptDir "_diskpart.tmp"
Set-Content -Path $diskPartScriptFile -Value $diskPartScriptContent
& diskpart.exe /s $diskPartScriptFile
& mountvol $mountPath /d
}
else{
Write-Warning "Not mounted"
}
Codifiquei o código do volume no meu script de montagem. Se alguém souber uma maneira de obter isso automaticamente, eu apreciaria.
Mas eu posso viver com isso agora, porque meu volume é sempre o mesmo.