I'm trying to get BitLocker information from a remote host. I used to do this using PowerShell (Get-BitLockerVolume) which would provide lots of useful information. When I try using C#, I don't get as much information back. Looking on Microsoft's website and from further research, I can't find anything to help me.
Does anyone know how to get the same output as Get-BitLockerVolume in C#?
By the way, this is what I've been testing within C#:
CimSession session = CimSession.Create(computerHostName);
IEnumerable<CimInstance> GI1 = session.QueryInstances(@"root\cimv2\Security\MicrosoftVolumeEncryption", "WQL", "SELECT * FROM Win32_EncryptableVolume");
foreach(CimInstance i in GI1)
{
Console.WriteLine("MountPoint: {0}, Protection: {1}",
i.CimInstanceProperties["DriveLetter"].Value,
i.CimInstanceProperties["ProtectionStatus"].Value);
}
As Jeroen recalls, you will be able to get that information calling methods on your WMI instances. As for the docs, Win32_EncryptableVolume
only exposes the following properties:
class Win32_EncryptableVolume
{
string DeviceID;
string PersistentVolumeID;
string DriveLetter;
uint32 ProtectionStatus;
};
To easily get the information you need using WMI and method access, you can use ORMi library:
You can define for example your class like this:
public class Win32_EncryptableVolume : WMIInstance
{
public string DeviceID {get; set;}
public string PersistentVolumeID {get; set;}
public string DriveLetter {get; set;}
public int ProtectionStatus {get; set;}
[WMIIgnore]
public int Version {get; set;}
public int GetVersion()
{
return WMIMethod.ExecuteMethod<int>(this)
}
}
Then you could do something like:
WmiHelper _helper = new WmiHelper("root\\Cimv2"); //Define the correct scope
List<Win32_EncryptableVolume> volumes = _helper.Query<Win32_EncryptableVolume>().ToList();
foreach(Win32_EncryptableVolume v in volumes)
{
v.Version = v.GetVersion();
}