Skip to content

Instantly share code, notes, and snippets.

@JaekelEDV
Created February 6, 2021 01:05
Show Gist options
  • Save JaekelEDV/6f7c37c46fca24ea923be9e0cc21a9d2 to your computer and use it in GitHub Desktop.
Save JaekelEDV/6f7c37c46fca24ea923be9e0cc21a9d2 to your computer and use it in GitHub Desktop.
New-BitLockerVhdx.ps1
#New-BitLockerVhdx.ps1, create a vhdx, enable BitLocker.
#->Share encrypted data between machines (mount, attach to VMs) and peers (vhdx->Stick)
#All with Windows standard tools.
throw "Nope. This is no script, just a bunch of cmdlets."
#Create a new vhdx
New-VHD -Path .\sec.vhdx -SizeBytes 1GB -Fixed
#Mount the vhdx
Mount-VHD -Path .\sec.vhdx
#Initialize,Partition,FS
Get-Disk -FriendlyName 'Msft Virtual Disk' |
Initialize-Disk -PartitionStyle GPT |
New-Partition -UseMaximumSize -DriveLetter 'S' |
Format-Volume -FileSystem NTFS -NewFileSystemLabel 'SEC'
#Enable-Bitlocker
$Pass = 'Password' | ConvertTo-SecureString -AsPlainText -Force
$BitLockerParams = @{
MountPoint = "S:"
EncryptionMethod = 'Aes256'
SkipHardwareTest = $true
PasswordProtector = $true
Password = $Pass
}
Enable-BitLocker @BitLockerParams
#You might want to add other protector methods with Add-BitLockerKeyProtector.
#Check: Dismount, mount fails, first unlock
Dismount-VHD -Path .\sec.vhdx
Mount-VHD -Path .\sec.vhdx
Unlock-BitLocker -MountPoint "S:" -Password $Pass
#Put the mount (and unlock, then think of how to store the password) commands in a startup/logon script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment