Coming from a traditional programming standpoint, I've always had a bit of a struggle scripting in PowerShell and figuring out what objects have which fields. It's super easy in an IDE in most languages to just look at the object fields.
I've been using Get-Member quite a lot lately which is very helpful at taking a stab and alleviating this frustration. However, I'm still having a bit of a hard time. Here's an example:
Command:
Get-BitLockerVolume | Get-Member
Output:
TypeName: Microsoft.BitLocker.Structures.BitLockerVolume
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AutoUnlockEnabled Property System.Nullable[bool] AutoUnlockEnabled {get;}
AutoUnlockKeyStored Property System.Nullable[bool] AutoUnlockKeyStored {get;}
CapacityGB Property float CapacityGB {get;}
ComputerName Property string ComputerName {get;}
EncryptionMethod Property Microsoft.BitLocker.Structures.BitLockerVolumeEncryptionMethodOnGet EncryptionMethod {get;}
EncryptionPercentage Property System.Nullable[float] EncryptionPercentage {get;}
KeyProtector Property System.Collections.ObjectModel.ReadOnlyCollection[Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtector] KeyProtector {get;}
LockStatus Property Microsoft.BitLocker.Structures.BitLockerVolumeLockStatus LockStatus {get;}
MetadataVersion Property int MetadataVersion {get;}
MountPoint Property string MountPoint {get;}
ProtectionStatus Property Microsoft.BitLocker.Structures.BitLockerVolumeProtectionStatus ProtectionStatus {get;}
VolumeStatus Property System.Nullable[Microsoft.BitLocker.Structures.BitLockerVolumeStatus] VolumeStatus {get;}
VolumeType Property Microsoft.BitLocker.Structures.BitLockerVolumeType VolumeType {get;}
WipePercentage Property System.Nullable[float] WipePercentage {get;}
Okay great. Now what if I want to see the fields of the KeyProtector field?
Here I try this:
Get-BitLockerVolume | % {$_.KeyProtector | Get-Member}
On a system where bitlocker volumes actually have a valid key protector field, I can get the results, since the piped results aren't null.
TypeName: Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtector
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AutoUnlockProtector Property System.Nullable[bool] AutoUnlockProtector {get;}
KeyCertificateType Property System.Nullable[Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtectorCertificate...
KeyFileName Property string KeyFileName {get;}
KeyProtectorId Property string KeyProtectorId {get;}
KeyProtectorType Property Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtectorType KeyProtectorType {get;}
RecoveryPassword Property string RecoveryPassword {get;}
Thumbprint Property string Thumbprint {get;}
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AutoUnlockProtector Property System.Nullable[bool] AutoUnlockProtector {get;}
KeyCertificateType Property System.Nullable[Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtectorCertificate...
KeyFileName Property string KeyFileName {get;}
KeyProtectorId Property string KeyProtectorId {get;}
KeyProtectorType Property Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtectorType KeyProtectorType {get;}
RecoveryPassword Property string RecoveryPassword {get;}
Thumbprint Property string Thumbprint {get;}
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AutoUnlockProtector Property System.Nullable[bool] AutoUnlockProtector {get;}
KeyCertificateType Property System.Nullable[Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtectorCertificate...
KeyFileName Property string KeyFileName {get;}
KeyProtectorId Property string KeyProtectorId {get;}
KeyProtectorType Property Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtectorType KeyProtectorType {get;}
RecoveryPassword Property string RecoveryPassword {get;}
Thumbprint Property string Thumbprint {get;}
How about on a system where I can't get away with this (most likely work around) solution? When no BitlockerVolume objects have a valid KeyProtector field, nothing is piped to Get-Member and it returns with an error.
What if I just want to view the properties of an object, where I don't have valid/instantiated objects to pass to the Get-Member cmdlet?