Исходя из традиционной точки зрения программирования, у меня всегда были проблемы с написанием сценариев в PowerShell и выяснением, какие объекты имеют какие поля. В большинстве языков в IDE очень просто смотреть на поля объекта.
В последнее время я довольно часто пользуюсь Get-Member
, что очень помогает при нанесении удара и облегчении этого расстройства. Тем не менее, мне все еще трудно. Вот пример:
Команда:
Get-BitLockerVolume | Get-Member
Выход:
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;}
Хорошо, отлично. А что если я хочу увидеть поля поля KeyProtector?
Здесь я пытаюсь это:
Get-BitLockerVolume | % {$_.KeyProtector | Get-Member}
В системе , где на томах с блокировщиками битов на самом деле имеется действительное поле защиты ключа , я могу получить результаты, поскольку результаты по конвейеру не равны нулю.
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;}
Как насчет системы, в которой мне не сходит с рук это (скорее всего, обходное решение)? Когда ни один объект BitlockerVolume не имеет действительного поля KeyProtector, ничто не передается в Get-Member и возвращается с ошибкой.
Что если я просто хочу просмотреть свойства объекта, где у меня нет действительных / созданных экземпляров объектов для передачи в командлет Get-Member?