0

I want to extract the ID from this command:

    manage-bde -protectors c: -get
    

The result of this command is:

Volume C: [Windows]
Tous les protecteurs de clés

    Mot de passe numérique :
      ID : {XXXXXXX-A315-42C6-9754-XXXXXXXXXX}
      Mot de passe :
        XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX

    TPM :
      ID : {XXXXXX-99B3-481B-B3FA-XXXXXXXXXXX}
      Profil de validation PCR :
        7, 11
        (Utilise le démarrage sécurisé pour la validation d’intégrité.)

I want only the ID from the "Mot de passe numérique" (first one, but on some PC, it's the second one) and not the "TPM"

I tried to do that with select-string, but it return both :/

Is there a way to "tell" to select-string to print only the ID after the "mot de passe numérique" expression ?

Thx :)

Eglyn
  • 3
  • 1
  • `Select-String` has a `-Context` parameter. Take a look here: [Get Previous Line while reading Log File in Powershell](https://stackoverflow.com/a/54362796/10223991) – T-Me Jan 27 '21 at 10:08
  • Does this answer your question? [Get Previous Line while reading Log File in Powershell](https://stackoverflow.com/questions/54362073/get-previous-line-while-reading-log-file-in-powershell) – T-Me Jan 27 '21 at 10:09

1 Answers1

0

Use Select-String's -Context parameter to indicate that you're interested in the lines surrounding a match:

$mbdeOutput = manage-bde -protectors c: -get

$mbdeOutput |Select-String 'Mot de passe numérique :' -Context 0,1 |ForEach-Object { $_.Context.PostContext[0] }

This should output the line immediately following Mot de passe numérique :

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Thx ! it works, i had to put "rique : " instead "Mot de passe numérique :", select-string does not like "é" character :) – Eglyn Jan 27 '21 at 10:20