简体   繁体   English

如何从powershell中的一行获取特定值

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

I'm trying to get a specific value out of the manage-bde -status C: command, which returns the following: BitLocker Drive Encryption: Configuration Tool version 10.0.18362 Copyright (C) 2013 Microsoft Corporation.我正在尝试从manage-bde -status C:命令中获取特定值,该命令返回以下内容:BitLocker 驱动器加密:配置工具版本 10.0.18362 版权所有 (C) 2013 Microsoft Corporation。 All rights reserved.版权所有。

Volume C: [] [OS Volume] 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

I'm trying to get the end of the line labelled Protection Status and return Off我正在尝试获得标有保护状态的行的末尾并返回Off

根据我的评论,我会改用Get-BitLockerVolume因为它返回一个更容易查询的对象:

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

If I understand correctly, you would like to check if it matches Off under Protection Status?如果我理解正确,您想检查它是否与保护状态下的关闭匹配? If so, here is an ugly piece of code I did it fast, but can get you what you want:如果是这样,这是我快速完成的一段丑陋的代码,但可以为您提供您想要的:

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

I used something similar to the post above to determine if BitLocker had been enabled over a drive from the manufacture which will always have unknown or none in the identification field.我使用了类似于上面帖子的内容来确定 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"
}

Please note that the line 'manage-bde -off C:' will decrypt the OS drive.请注意,“manage-bde -off C:”行将解密操作系统驱动器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM