-1

I need to scan the Bitlocker status in a relatively large environment and would like the output in a structured CSV file. This is what I have so far, but it seems to be hanging when executed.

    $Computers = Get-Content -Path "C:\script\allComputers.txt"
$bdeObject = @()
foreach ($computer in $Computers) {
        $bde = manage-bde -cn $computer -status C:

            $Name = $bde | Select-String "Computer Name:" 
            $Name = ($ComputerName -split ": ")[1]

            $Status = $bde | Select-String "Conversion Status:"
            $Status = ($ConversionStatus -split ": ")[1]
            $Status = $ConversionStatus -replace '\s',''

            $Encrypted = $bde | Select-String "Percentage Encrypted:"
            $Encrypted = ($PercentageEncrypted -split ": ")[1]

            $Method = $bde | Select-String "Encryption Method:"
            $Method = ($Method -split ": ")[1]

            $Version = $bde | Select-String "Bitlocker Version:"
            $Version = ($Version -split ": ")[1]

            $Size = $bde | Select-String "Size:"
            $Size = ($Size -split ": ")[1]

        #Add all fields to an array that contains custom formatted objects with desired fields
        $bdeObject += New-Object psobject -Property @{'Computer Name'=$Name; 'Conversion Status'=$Status; 'Percentage Encrypted'=$Encrypted; 'Encryption Method'=$Method; 'Bitlocker Version'=$Version; 'Size'=$Size;}
    }
$bdeObject | Export-CSV C:\script\output.csv -Append -NoTypeInformation

Any guidance here will be appreciated

  • 1
    Using the syntax `$bdeObject +=` is going to be slow for a large list of computers. Instead set `$bdeObject = foreach .... ` where your loop begins. Then just output your `New-Object` command at the end of the loop. This could still backfire if you don’t have enough memory to support the output of your loop. In summary, replace `foreach` with `$bdeObject = foreach` and remove `$bdeObject +=`. – AdminOfThings Jun 27 '20 at 22:14

1 Answers1

0

Thank you for the help. I managed to get the required output.

   $Computers = Get-Content -Path "C:\script\allComputers.txt"
$bdeObject = foreach ($computer in $Computers) {
        $bde = manage-bde -cn $computer -status C:
            $Name = $Computer
            $Status = $bde | Select-String "Conversion Status:"
            $Status = ($Status -split ": ")[1]
            $Status = $Status -replace '\s',''
            $Encrypted = $bde | Select-String "Percentage Encrypted:"
            $Encrypted = ($Encrypted -split ": ")[1]
            $Method = $bde | Select-String "Encryption Method:"
            $Method = ($Method -split ": ")[1]
            $Version = $bde | Select-String "Bitlocker Version:"
            $Version = ($Version -split ": ")[1]
            $Size = $bde | Select-String "Size:"
            $Size = ($Size -split ": ")[1]
            $Key = $bde | Select-String "Key Protectors:"
            $Key = ($Key -split ": ")[1]
     
        #Add all fields to an array that contains custom formatted objects with desired fields
        New-Object psobject -Property @{'Computer Name'=$Name;'Key Protectors'=$Key; 'Conversion Status'=$Status; 'Percentage Encrypted'=$Encrypted; 'Encryption Method'=$Method; 'Bitlocker Version'=$Version; 'Size'=$Size;}
    }
$bdeObject | Export-CSV C:\script\bdeStatus.csv -NoTypeInformation -Force