Combreal

GetBitLockerRecoveryPassword.ps1

Mar 6th, 2021 (edited)
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
  2. [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
  3.  
  4. If (-Not (Test-Connection ad.dbs.fr -Quiet))
  5. {
  6.     $output = [System.Windows.Forms.MessageBox]::Show("Please connect to the DBS network first", "Error occured" , '0',  'Error')
  7.     If ($output -eq "OK")
  8.     {
  9.         Exit
  10.     }
  11. }
  12. If (-Not (whoami | findstr -i "adm"))
  13. {
  14.     $output = [System.Windows.Forms.MessageBox]::Show("Please run the program as adm", "Error occured" , '0',  'Error')
  15.     If ($output -eq "OK")
  16.     {
  17.         Exit
  18.     }
  19. }
  20.  
  21. Function Child ($Parentlabel)
  22. {
  23.     $objComputer = Get-ADComputer $Parentlabel.TEXT
  24.     $BitlockerObject = Get-ADObject -Filter {objectclass -eq 'msFVE-RecoveryInformation'} -SearchBase $objComputer.DistinguishedName -Properties 'msFVE-RecoveryPassword'
  25.     $BitlockerObject = $BitlockerObject | Select-Object -Property ObjectGUID, msFVE-RecoveryPassword | Select-Object @{Label="ID";Expression={$_.ObjectGUID}}, @{Label="Recovery Key";Expression={$_."msFVE-RecoveryPassword"}} | Format-List | Out-String
  26.  
  27.  
  28.     $bitlockerGUIbis = New-Object system.Windows.Forms.Form
  29.     $bitlockerGUIbis.Text = "GetBitlockerKeys"
  30.     $bitlockerGUIbis.Name = "GBK"
  31.     $bitlockerGUIbis.DataBindings.DefaultDataSourceUpdateMode = 0
  32.     $bitlockerGUIbis.ClientSize = New-Object System.Drawing.Size(590,224)
  33.     $iconBase64 = 'AAAA'
  34.     $iconBytes = [Convert]::FromBase64String($iconBase64)
  35.     $stream = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
  36.     $stream.Write($iconBytes, 0, $iconBytes.Length);
  37.     $iconImage = [System.Drawing.Image]::FromStream($stream, $true)
  38.     $bitlockerGUIbis.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())
  39.     $bitlockerGUIbis.Add_Closing({[System.Windows.Forms.Application]::Exit($null)})  
  40.        
  41.     $recoveryKeyField = New-Object System.Windows.Forms.RichTextBox
  42.     $recoveryKeyField.ClientSize = New-Object System.Drawing.Size(562,160)
  43.     $recoveryKeyField.Location = New-Object System.Drawing.Point(13,13)
  44.     $recoveryKeyField.Font = [System.Drawing.Font]::new('Calibri', 12)
  45.     $recoveryKeyField.Anchor = 'Top','Right','Bottom','Left'
  46.     $recoveryKeyField.Text = [string]$BitlockerObject
  47.     #$recoveryKeyField.Text = "601381-464343-357159-585849-665588-463507-119416-469931"
  48.     #$recoveryKeyField.AppendText("`nhi")
  49.     $bitlockerGUIbis.Controls.Add($recoveryKeyField)
  50.    
  51.     $copyToCBButton = New-Object System.Windows.Forms.Button
  52.     $copyToCBButton.ClientSize = New-Object System.Drawing.Size(565,23)
  53.     $copyToCBButton.Location = New-Object System.Drawing.Point(13,190)
  54.     $copyToCBButton.Text = "Copy to Clipboard"
  55.     $copyToCBButton.DataBindings.DefaultDataSourceUpdateMode = 0
  56.     $copyToCBButton.Add_Click({Echo $recoveryKeyField.SelectedText | Clip; [System.Windows.Forms.Application]::Exit($null)})
  57.     $bitlockerGUIbis.Controls.Add($copyToCBButton)
  58.  
  59.     $bitlockerGUIbis.ShowDialog()
  60. }
  61.  
  62. $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  63.  
  64. $bitlockerGUI = New-Object System.Windows.Forms.Form
  65. $bitlockerGUI.Text = "GetBitlockerKeys"
  66. $bitlockerGUI.Name = "GBK"
  67. $bitlockerGUI.DataBindings.DefaultDataSourceUpdateMode = 0
  68. $bitlockerGUI.ClientSize = New-Object System.Drawing.Size(270,100)
  69. $iconBase64 = 'AAA=='
  70. $iconBytes = [Convert]::FromBase64String($iconBase64)
  71. $stream = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
  72. $stream.Write($iconBytes, 0, $iconBytes.Length);
  73. $iconImage = [System.Drawing.Image]::FromStream($stream, $true)
  74. $bitlockerGUI.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())
  75.  
  76. $machineNameLabel = New-Object System.Windows.Forms.Label
  77. $machineNameLabel.Name = "machineNameLabel"
  78. $machineNameLabel.Size = New-Object System.Drawing.Size(240,23)
  79. $machineNameLabel.Text = "Enter the machine name :"  
  80. $System_Drawing_Point = New-Object System.Drawing.Point
  81. $System_Drawing_Point.X = 13
  82. $System_Drawing_Point.Y = 13
  83. $machineNameLabel.Location = $System_Drawing_Point
  84. $machineNameLabel.DataBindings.DefaultDataSourceUpdateMode = 0
  85. $bitlockerGUI.Controls.Add($machineNameLabel)
  86.  
  87. $machineNameEdit = New-Object System.Windows.Forms.TextBox
  88. $machineNameEdit.Name = "MachineNameEdit"
  89. $machineNameEdit.Size = New-Object System.Drawing.Size(155,23)
  90. $machineNameEdit.Text = "DUBB"  
  91. $System_Drawing_Point = New-Object System.Drawing.Point
  92. $System_Drawing_Point.X = 13
  93. $System_Drawing_Point.Y = 37
  94. $machineNameEdit.Location = $System_Drawing_Point
  95. $machineNameEdit.DataBindings.DefaultDataSourceUpdateMode = 0
  96. $bitlockerGUI.Controls.Add($machineNameEdit)
  97.  
  98. $getKeyButton = New-Object System.Windows.Forms.Button
  99. $getKeyButton.TabIndex = 0
  100. $getKeyButton.Name = "GetKeysButton"
  101. $getKeyButton.Size = New-Object System.Drawing.Size(240,23)
  102. $getKeyButton.UseVisualStyleBackColor = $True  
  103. $getKeyButton.Text = "Get the recovery key(s)"  
  104. $System_Drawing_Point = New-Object System.Drawing.Point
  105. $System_Drawing_Point.X = 13
  106. $System_Drawing_Point.Y = 69
  107. $getKeyButton.Location = $System_Drawing_Point
  108. $getKeyButton.DataBindings.DefaultDataSourceUpdateMode = 0
  109. $getKeyButton.add_Click({Child $machineNameEdit})
  110. $bitlockerGUI.Controls.Add($getKeyButton)
  111.  
  112. $InitialFormWindowState = $bitlockerGUI.WindowState
  113. $bitlockerGUI.add_Load({$bitlockerGUI.WindowState = $InitialFormWindowState})
  114. $bitlockerGUI.ShowDialog()| Out-Null    
Add Comment
Please, Sign In to add comment