Skip to content

Instantly share code, notes, and snippets.

@MusiCode1
Last active May 16, 2021 10:38
Show Gist options
  • Save MusiCode1/e5e46b467b4a18b93e44ae0ed6c1296f to your computer and use it in GitHub Desktop.
Save MusiCode1/e5e46b467b4a18b93e44ae0ed6c1296f to your computer and use it in GitHub Desktop.

bitwarden vhdx password

param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
$file = "F:\encoded\disk.vhdx"
if ((Test-Admin) -eq $false) {
if ($elevated) {
# tried to elevate, did not work, aborting
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
exit
}
}
Lock-BitLocker e:
Dismount-VHD -Path $file
stop-process -Id $PID
param([switch]$Elevated)
# ==== pubemh ==== #############################################################
# הרצת הסקריפט כמנהל
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function run_as_admin {
}
function get_password_gui {
$title = "סיסמת bw"
$window_text = "אנא הזן את סיסמת bw"
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = $title
$form.Size = New-Object System.Drawing.Size(300, 200)
$form.StartPosition = 'CenterScreen'
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75, 120)
$okButton.Size = New-Object System.Drawing.Size(75, 23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150, 120)
$cancelButton.Size = New-Object System.Drawing.Size(75, 23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 20)
$label.Size = New-Object System.Drawing.Size(280, 20)
$label.Text = $window_text
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10, 40)
$textBox.Size = New-Object System.Drawing.Size(260, 20)
$textBox.PasswordChar = "*"
$form.Controls.Add($textBox)
$form.Topmost = $true
$form.Add_Shown( { $textBox.Select() })
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$x = $textBox.Text
$x
}
}
# === הסקריפט === #############################################################
$sync = $false
$latter = "e:"
$file = "F:\encoded\disk.vhdx"
$bitwarden_item_name = "Encripted-disk"
if ((Test-Admin) -eq $false) {
if ($elevated) {
# tried to elevate, did not work, aborting
throw "error!"
}
else {
"dddd"
"{0}"
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
'running with full privileges'
$bw_password = get_password_gui
if ($null -eq $bw_password) {
throw 'no pass!'
}
$session = (bw unlock $bw_password --raw)
if ($null -eq $session) {
throw 'Invalid master password'
}
if ($sync) {
bw sync --session $session
}
$password = (bw get password $bitwarden_item_name --session $session)
Mount-VHD -Path $file
Unlock-Bitlocker $latter -Password (ConvertTo-SecureString $password -AsPlainText -Force)
Start-Process $latter
stop-process -Id $PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment