Public/Get-ADComputerBitLockerInfo.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#Requires -Modules ActiveDirectory
#Requires -Version 3.0


Function Get-ADComputerBitLockerInfo () {   

<#
.SYNOPSIS
 Get Computer BitLocker Recovery Information from Active Directory.
  
.DESCRIPTION
 Get BitLocker Recovery Information from Active Directory.
 ComputerName;PasswordID;RecoveryPassword;Date and Time
 
 Requirement:
    - ActiveDirectory PowerShell Module
    - Needed rights to view AD BitLocker Recovery Info
  
 Usage:
     
    Get-ADComputerBitLockerInfo -ComputerName Computer1
    Get-ADComputerBitLockerInfo Computer1, Computer2
 
 
.PARAMETER ComputerName
    Optional parameter to view computer Bitlocker info
 
 
.EXAMPLE
   Get-ADComputerBitLockerInfo -ComputerName Computer1
 
   Description
   -----------
   Get BitLocker Recovery Info for computer
 
    
.EXAMPLE
   Get-ADComputerBitLockerInfo Computer1, Computer2
 
   Description
   -----------
   Get BitLocker Recovery Info for computers
 
 
.NOTES
   File Name : Get-ADComputerBitLockerInfo.ps1
   Version : 2.1912
   Author : Andriy Zarevych
 
   Find me on :
   * My Blog : https://angry-admin.blogspot.com/
   * LinkedIn : https://linkedin.com/in/zarevych/
   * Github : https://github.com/zarevych
 
   Change Log:
   V2.1912 : Initial version
#>


    [CmdletBinding()]
    [OutputType([pscustomobject])]
    [Alias('Get-ADComputerBitLocker')]
    
    param(

        [Parameter(ValueFromPipeline=$true,
        ValueFromPipelineByPropertyName=$true,
        Position=0)]
        [ValidateNotNullOrEmpty()]
        [Alias('Computer','Name')]
        [String[]]$ComputerName = $env:ComputerName

    )
  

    Process {
        
        $Computers = $ComputerName

        ForEach ($Computer in $Computers) {

            $BitLockerInfo = @()

            try {
                $Computer = Get-ADComputer $Computer -Property * -ErrorAction Stop
            }
            catch {
                #Write-Error $_.Exception.Message
                Write-Host $_.Exception.Message`n -ForegroundColor Red
                #Break
                Continue
            }


            # Get BitLocker Info
            $BitLockerObjects=(Get-ADObject -Filter {objectclass -eq 'msFVE-RecoveryInformation'} -SearchBase $Computer.DistinguishedName -Properties whenCreated, msFVE-RecoveryPassword | Sort whenCreated -Descending)
            
            foreach ($BitLockerObject in $BitLockerObjects) {
            #The name of the BitLocker recovery object incorporates a globally unique identifier (GUID) and date and time information,
            #for a fixed length of 63 characters. The form is: <Object Creation Date and Time><Recovery GUID>
            #For example:
            #2005-09-30T17:08:23-08:00{063EA4E1-220C-4293-BA01-4754620A96E7}
            #$BitLockerObject.Name
                
                $strComputerDate = $BitLockerObject.Name.Substring(0,10)
                $strComputerTime = $BitLockerObject.Name.Substring(11,8)
                $strComputerGMT = $BitLockerObject.Name.Substring(19,6)
                $strComputerPasswordID = $BitLockerObject.Name.Substring(26,36)
                $strComputerRecoveryPassword = $BitLockerObject.'msFVE-RecoveryPassword'
                
                #$strComputerDate = $BitLockerObject.Name.Substring(0,10) + ' ' + $BitLockerObject.Name.Substring(11,8) + ' ' + $BitLockerObject.Name.Substring(19,6)
                
                $BitLockerInfo += [PSCustomObject]@{
                    Name = $Computer.Name
                    PasswordID = $BitLockerObject.Name.Substring(26,36)
                    RecoveryPassword = $BitLockerObject.'msFVE-RecoveryPassword'
                    Date = $BitLockerObject.Name.Substring(0,10) + ' ' + $BitLockerObject.Name.Substring(11,8) + ' ' + $BitLockerObject.Name.Substring(19,6)
                }

            }

            # Return BitLocker data
            $BitLockerInfo
        }
               
    }

}