-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ADComputers-BitLockerInfo.ps1
More file actions
213 lines (145 loc) · 6.77 KB
/
Copy pathGet-ADComputers-BitLockerInfo.ps1
File metadata and controls
213 lines (145 loc) · 6.77 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<#PSScriptInfo
.VERSION 2.0
.GUID 5df64425-ed5b-489d-813b-936a6865c6a5
.AUTHOR Andriy Zarevych
.COMPANYNAME
.COPYRIGHT (c) 2016 Andriy Zarevych
.TAGS ActiveDirectory BitLocker
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES ActiveDirectory
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>
<#
.SYNOPSIS
Get BitLocker Recovery Information from Active Directory.
Generates a CSV file with computer names and BitLocker Recovery Keys.
.DESCRIPTION
Get BitLocker Recovery Information from Active Directory.
Generates a CSV file with computer names and BitLocker Recovery Keys:
ComputerName;OperatingSystem;Date;Time;GMT;PasswordID;RecoveryPassword;DistinguishedName
Requirement of the script:
- ActiveDirectory PowerShell Module
- Needed rights to view AD BitLocker Recovery Info
Usage:
.\Get-ADComputers-BitLockerInfo.ps1
.\Get-ADComputers-BitLockerInfo.ps1 -OU "OU=Computers,OU=IT Department,DC=myDomain,DC=com"
Recommendation is to run this script as a schedule task to have backup your BitLocker Recovery keys
In Section Initialisations you may set default value:
to set default value for OU
[string]$OU =
to set default name for a CSV file
[string]$LogFileName =
to set default path for a CSV file
[string]$LogFilePath =
.PARAMETER OU
Optional parameter to narrow the scope of the script
.PARAMETER LogFilePath
Optional parameter to set path for log files
Example: -LogFilePath "C:\Scripts"
.PARAMETER LogFileName
Optional parameter to set name for log files
.EXAMPLE
.\Get-ADComputers-BitLockerInfo.ps1
Description
-----------
Generates a CSV file with computer names and BitLocker Recovery Keys
.EXAMPLE
.\Get-ADComputers-BitLockerInfo.ps1 -OU "OU=Computers,OU=IT Department,DC=myDomain,DC=com"
Description
-----------
Generates a CSV file with computer names and BitLocker Recovery Keys for computers in targed OU
.EXAMPLE
.\Get-ADComputers-BitLockerInfo.ps1 -OU "OU=Computers,OU=IT Department,DC=myDomain,DC=com" -LogFilePath "C:\Scripts" -LogFileName "BitlockerInfo.csv"
Description
-----------
Generates a CSV file with specific name and path
.NOTES
File Name : Get-ADComputers-BitLockerInfo.ps1
Version : 2.0
Date : 2018.07.03
Author : Andriy Zarevych
Find me on :
* My Blog : https://angry-admin.blogspot.com/
* LinkedIn : https://linkedin.com/in/zarevych/
* Github : https://github.com/zarevych
#>
#Requires -Modules ActiveDirectory
#Requires -Version 2.0
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false, HelpMessage="Enter OU, example: OU=Computers,OU=ITDep,DC=contoso,DC=com", ValueFromPipelineByPropertyName=$true)]
[string]$OU,
[Parameter(Mandatory=$false, HelpMessage="Enter path for log file, example: C:\Scripts", ValueFromPipelineByPropertyName=$true)]
[string]$LogFilePath = "\\HOSTNAME\BitLocker Backups\AD_EXPORT",
[Parameter(Mandatory=$false, HelpMessage="Enter log file Name", ValueFromPipelineByPropertyName=$true)]
[string]$LogFileName = "BitLockerInfo_$(Get-Date -f 'yyyy-MM-dd').csv"
)
#----------------------------------------------------------[Declarations]----------------------------------------------------------
Import-Module ActiveDirectory
#To separating fields for report
$strDelimiter = ";"
if (-Not (Test-Path -PathType Container $LogFilePath)){
$LogFilePath = New-Item -ItemType Directory -Force -Path $LogFilePath
}
if ($LogFilePath.Substring($LogFilePath.Length-1) -eq "\" -or $LogFilePath.Substring($LogFilePath.Length-1) -eq "/"){
}
else {
$LogFilePath = $LogFilePath + "\"
}
$LogFile = $LogFilePath + $LogFileName
#-----------------------------------------------------------[Execution]------------------------------------------------------------
#Report file $LogFile
if (Test-Path $LogFile){
#Remove-Item $LogFile
Clear-Content $LogFile
}
else {
$LogFile = New-Item -Path $LogFilePath -Name $LogFileName -ItemType File
}
#
write-host
write-host "Script start" $(Get-Date)
write-host
#Set scope
#Get computers info
if ($OU -ne "") {
Write-Host "Organizational Unit:" $OU
$Computers = Get-ADComputer -Filter 'ObjectClass -eq "computer"' -Property * -SearchBase $OU
}
else {
Write-Host "Domain:" $env:userdnsdomain
$Computers = Get-ADComputer -Filter 'ObjectClass -eq "computer"' -Property *
}
write-host "Report File Path:" $LogFile
#Write report header
$strToReport = "ComputerName" + $strDelimiter + "OperatingSystem" + $strDelimiter + "Date" + $strDelimiter + "Time" + $strDelimiter + "GMT" + $strDelimiter + "PasswordID" + $strDelimiter + "RecoveryPassword" + $strDelimiter + "DistinguishedName"
Add-Content $LogFile $strToReport
#Get BitLocker Recovery Info
#Write report
foreach ($Computer in $Computers) {
$BitLockerObjects=(Get-ADObject -Filter {objectclass -eq 'msFVE-RecoveryInformation'} -SearchBase $Computer.DistinguishedName -Properties msFVE-RecoveryPassword)
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'
#$strToReport = $Computer.Name + $delimiter + $Computer.OperatingSystem + $delimiter + $strComputerDate + $delimiter + $strComputerTime + $delimiter + $strComputerGMT + $delimiter + $strComputerPasswordID + $delimiter + $strComputerRecoveryPassword + $delimiter + $Computer + $delimiter + $BitLockerObject
$strToReport = $Computer.Name + $strDelimiter + $Computer.OperatingSystem + $strDelimiter + $strComputerDate + $strDelimiter + $strComputerTime + $strDelimiter + $strComputerGMT + $strDelimiter + $strComputerPasswordID + $strDelimiter + $strComputerRecoveryPassword + $strDelimiter + $Computer.DistinguishedName
Add-Content $LogFile $strToReport
}
}
write-host
write-host "Script end" $(Get-Date)
write-host