#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
import ctypes
import os

# Specify the drive for which you want to retrieve the recovery key
drive = "C:"  # Change this to the desired drive letter

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection

    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))

    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

# PowerShell command to retrieve the BitLocker recovery key
ps_command = r'manage-bde -protectors -get ' + drive + ' -type RecoveryPassword'

try:
    with disable_file_system_redirection():
        result = os.popen('powershell "%s"' % ps_command).read()

    print("----------------------------------------------------------------------------")
    print("Device Name: ", os.environ.get('COMPUTERNAME', 'Unknown'))
    print("----------------------------------------------------------------------------")
    if result:
        print(result.strip())
    else:
        print("No output from the command. Ensure BitLocker is enabled on the specified drive.")
    print("----------------------------------------------------------------------------")

except Exception as e:
    print("An error occurred:", str(e))
