New to Powershell - help understanding pipeline

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #5178

    by scriptwriter3 at 2012-10-08 08:49:17

    I am new to Powershell and having trouble working with pipelines. I am trying to get some details about BitLocker encryption status for use in a script.

    Step #1
    ———-
    I begin by setting up a WMI connection to the Win32_EncryptableVolume class
    $HardDriveEncryption = Get-Wmiobject -namespace root\CIMv2\Security\MicrosoftVolumeEncryption -class Win32_EncryptableVolume -Filter "DriveLetter='C:'"

    Step #2
    ———
    The next step is to get the VolumeKeyProtectorID values (as output) from the GetKeyProtectors method
    $HardDriveEncryption.GetKeyProtectors()

    The output from this command is
    VolumeKeyProtectorID : {{314E8035-4B7C-402C-87C1-9F9B94759E86}, {44DE96F0-8C63-471A-94F1-2B35347433C9}}

    Step #3
    ———-
    Using the VolumeKeyProtectorID values as input to the GetKeyProtectorType method I can then get the KeyProtectorType value. The end goal is to get the KeyProtectorType value.
    $HardDriveEncryption.GetKeyProtectorType("{314E8035-4B7C-402C-87C1-9F9B94759E86}")

    The output from this command is
    KeyProtectorType : 1

    Now thats all fine and dandy but I need to script this and thats where I am getting lost. I have tried
    $HardDriveEncryption.GetKeyProtectors() | $HardDriveEncryption.GetKeyProtectorType("$_.VolumeKeyProtectorID")
    but that didn't work. So then I tried
    $HardDriveEncryption.GetKeyProtectors() | foreach-object { $HardDriveEncryption.GetKeyProtectorType($_.VolumeKeyProtectorID) }
    but that didn't work either. What am I missing??

    by coderaven at 2012-10-08 15:49:51

    Your step 1 looks good.

    Looking at the output from Step 2 in your process you see 2 {} around the Volume Key Protector IDs. The way I get to pull this data out is using the Select-Object command with -ExpandProperty as follows:

    $HardDriveEncryption.GetKeyProtectors() | Select-Object -ExpandProperty VolumeKeyProtectorID

    After this you can keep piping but will have to reference the $HardDriveEncryption if you want root level information.

    by scriptwriter3 at 2012-10-08 20:08:14

    coderaven – thanks for the quick reply and the excellent information!

    In case anyone else comes across this post, here is how I combined steps #2 and #3 together

    $HardDriveEncryption.GetKeyProtectors() | Select-Object -ExpandProperty VolumeKeyProtectorID | foreach-object { $HardDriveEncryption.GetKeyProtectorType($_) } | Select-Object KeyProtectorType

You must be logged in to reply to this topic.