-
Notifications
You must be signed in to change notification settings - Fork 95
/
Get-BitLockerInfo.ps1
37 lines (30 loc) · 1.3 KB
/
Get-BitLockerInfo.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
# requires psexec
function Get-BitLockerInfo {
param (
[string]$ComputerName = $env:COMPUTERNAME,
[string]$PsExecPath = 'C:\pstools\psexec.exe'
)
# Test connectivity before attempting to connect
if (Test-Connection -ComputerName $ComputerName -Quiet -Count 2) {
try{
$user = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ComputerName ).UserName
}
catch {
$user = 'UNKNOWN'
}
$hash = [ordered]@{
'ComputerName' = $ComputerName
'User' = $user
}
# manage-bde -status c: -computername $comp.name # can't use because of the context it says manage-bde not found
# With this parsing of the output of 'manage-bde' we ensure it works on systems using languages other than English, and it's more robust and efficient in general
$bitlockerinfo = (& $PsExecPath \\$ComputerName manage-bde -status c:) -replace ':','=' | Where-Object { $_ -match "^(\s{4})" } | ConvertFrom-StringData
foreach ($key in $bitlockerinfo.Keys) {
$hash.Add("$key", $bitlockerinfo."$key")
}
# return the created object
[PSCustomObject]$hash
} else {
Write-Error "Could not reach target computer: '$ComputerName'."
}
}