【问题标题】:Remote Bitlocker status scan - CSV Output远程 Bitlocker 状态扫描 - CSV 输出
【发布时间】:2020-10-18 05:40:53
【问题描述】:

我需要在相对较大的环境中扫描 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

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

【问题讨论】:

  • 使用语法 $bdeObject += 对于大量计算机来说会很慢。而是在循环开始的地方设置$bdeObject = foreach .... 。然后在循环结束时输出你的New-Object 命令。如果您没有足够的内存来支持循环的输出,这仍然可能适得其反。总之,将foreach 替换为$bdeObject = foreach 并删除$bdeObject +=

标签: powershell csv bitlocker


【解决方案1】:

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

   $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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 2016-02-09
    相关资源
    最近更新 更多