簡體   English   中英

如何從powershell中的一行獲取特定值

[英]How do I get a specific value from a line in powershell

我正在嘗試從manage-bde -status C:命令中獲取特定值,該命令返回以下內容:BitLocker 驅動器加密:配置工具版本 10.0.18362 版權所有 (C) 2013 Microsoft Corporation。 版權所有。

C 卷:[] [操作系統卷]

Size:                 237.29 GB
BitLocker Version:    None
Conversion Status:    Fully Decrypted
Percentage Encrypted: 0.0%
Encryption Method:    None
Protection Status:    Protection Off
Lock Status:          Unlocked
Identification Field: None
Key Protectors:       None Found

我正在嘗試獲得標有保護狀態的行的末尾並返回Off

根據我的評論,我會改用Get-BitLockerVolume因為它返回一個更容易查詢的對象:

Get-BitLockerVolume -MountPoint C: | Select-Object -ExpandProperty ProtectionStatus

如果我理解正確,您想檢查它是否與保護狀態下的關閉匹配? 如果是這樣,這是我快速完成的一段丑陋的代碼,但可以為您提供您想要的:

$status = manage-bde -status C: | Select-String 'Protection'
if ($status -match 'Off'){
Write-Output $true
} else {
Write-Host $false
}

我使用了類似於上面帖子的內容來確定 BitLocker 是否已通過制造商的驅動器啟用,該驅動器在識別字段中總是未知或沒有。

# Check for OEM configuration of BitLocker

$blidfield = manage-bde -status C: | Select-String 'Identification Field'
$bloemencrypted = manage-bde -status C: | Select-String 'Conversion Status'
if ($blidfield -match 'None' -or $blidfield -match 'Unknown' -and ($bloemencrypted -match 'Fully Encrypted' -or $bloemencrypted -match 'Used Space Only Encrypted')){
    Write-Log "BitLocker appears to be configured with OEM configuration, Starting to decrypt."
    manage-bde -off C:
    exit
} else {
    Write-Log "BitLocker doesn't appear to be configured with OEM configuration"
}

請注意,“manage-bde -off C:”行將解密操作系統驅動器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM