-1

我需要在相对较大的环境中扫描 Bitlocker 状态,并希望以结构化 CSV 文件的形式输出。这是我到目前为止所拥有的,但在执行时它似乎挂起。

    $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

这里的任何指导将不胜感激

4

1 回答 1

0

感谢您的帮助。我设法获得了所需的输出。

   $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
于 2020-06-29T10:26:40.747 回答