4

I have written bitlocker code to backup key after old key has been shared with user.

My requirement is that don't want to display WARNING: ACTIONS REQUIRED: while running script

enter image description here

$BLV = Get-BitLockerVolume -MountPoint "C:"
$KeyProt = $BLV.KeyProtector | Where-object{$_.KeyProtectorType -eq "RecoveryPassword"}
$KeyProt.KeyProtectorId
Remove-BitlockerKeyProtector -MountPoint "C:" -KeyProtectorId $KeyProt.KeyProtectorId
Add-BitLockerKeyProtector -MountPoint "C:" -RecoveryPasswordProtector
$BLV = Get-BitLockerVolume -MountPoint "C:"
$KeyProt = $BLV.KeyProtector | Where-object{$_.KeyProtectorType -eq "RecoveryPassword"}
$KeyProt.KeyProtectorId
Backup-BitLockerKeyProtector -MountPoint "C:" -KeyProtectorId $KeyProt.KeyProtectorId
Resume-BitLocker -MountPoint "C:"
Suraj Kumar
  • 153
  • 6

1 Answers1

3

Windows PowerShell has many more streams than Linux.

Here's the list from Microsoft's about_Redirection:

enter image description here

You may redirect all streams using the wildcard *>$null. You may also use a file instead of $null.

Reference : Redirecting output to $null in PowerShell, but ensuring the variable remains set.


An alternative is to add to the Add-BitLockerKeyProtector command the parameter -ErrorVariable out to store the error message in variable out.

Or if this isn't an error message, perhaps -InformationVariable out.

For more information see about_CommonParameters.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • i don't want to redirect. i don't want it to display – Suraj Kumar Jan 05 '23 at 11:56
  • 1
    Try adding the parameter `-ErrorVariable out` to store the error message in variable `out`. Or if this isn't an error message, perhaps `-InformationVariable out`. [link](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.3) – harrymc Jan 05 '23 at 12:06
  • @SurajKumar - So what was the full command? – Ramhound Jan 05 '23 at 12:35
  • Linux has up to 256 file descriptors (streams in your terminology). They can be created and destroyed at will, but default to 3 - stdout, stdin and stderr. – Canadian Luke Jan 05 '23 at 18:09