【问题标题】:Using Powershell to Suspend Bitlocker - Getting error使用 Powershell 暂停 Bitlocker - 出现错误
【发布时间】:2018-08-02 19:09:11
【问题描述】:

我正在部署一个包来暂停 bitlocker,然后在我们的许多 HP 系统上应用 BIOS 更新。该脚本在大约 90-95% 的系统上运行正常,但有大约 5-10% 的系统出现故障。

这是我正在使用的脚本:

#Create Variable of Bitlocker Status
$Volume = Get-WmiObject -Namespace root\cimv2\security\microsoftvolumeencryption -Query "select * from win32_encryptablevolume where DriveLetter = 'C:'"
$Status = $Volume.GetProtectionStatus()
$BitLockerStatus = $status.ProtectionStatus


#Check if Bilocker enabled, then suspend.
If ($BitlockerStatus -eq '1'){$Volume.DisableKeyProtectors()}
$Status = $Volume.GetProtectionStatus()
$BitLockerStatus = $status.ProtectionStatus
If($BitLockerStatus -eq '1'){
    mofcomp.exe c:\windows\system32\wbem\win32_encryptablevolume.mof
    Manage-bde.exe -protectors -disable c:
}

#Update Variable of Bitlocker Status
$BitLockerStatus = $status.ProtectionStatus

这是错误:

Message        : You cannot call a method on a null-valued expression.
InnerException : 

FullyQualifiedErrorId : InvokeMethodOnNull
ScriptStackTrace      : at <ScriptBlock>, 
                        C:\Windows\ccmcache\75\Deploy-Application.ps1: line 129
                        at <ScriptBlock>, <No file>: line 1
                        at <ScriptBlock>, <No file>: line 1

``PositionMessage : At C:\Windows\ccmcache\75\Deploy-Application.ps1:129 char:9
                  +         $Status = $Volume.GetProtectionStatus()
                  +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

我明白了错误的含义,但我感到困惑的是,为什么只有少数几个系统会出现故障。

【问题讨论】:

  • 所有系统都运行相同的 Windows 版本吗?
  • Win10 和 Win7 的混合。据我所知,问题似乎出在 Win7 上。

标签: powershell bitlocker


【解决方案1】:

只需测试$Volume 是否不是$null(无论如何这是最佳实践)。 WMI 查询将出于多种原因返回 $null,例如从不兼容的 Windows 版本到没有有效的 C: 可加密卷等,从而导致您的错误。

#Create Variable of Bitlocker Status
$Volume = Get-WmiObject -Namespace root\cimv2\security\microsoftvolumeencryption -Query "select * from win32_encryptablevolume where DriveLetter = 'C:'"

if($Volume)
{

    $Status = $Volume.GetProtectionStatus()
    $BitLockerStatus = $status.ProtectionStatus


    #Check if Bilocker enabled, then suspend.
    If ($BitlockerStatus -eq '1'){$Volume.DisableKeyProtectors()}
    $Status = $Volume.GetProtectionStatus()
    $BitLockerStatus = $status.ProtectionStatus
    If($BitLockerStatus -eq '1'){
        mofcomp.exe c:\windows\system32\wbem\win32_encryptablevolume.mof
        Manage-bde.exe -protectors -disable c:
    }

    #Update Variable of Bitlocker Status
    $BitLockerStatus = $status.ProtectionStatus

}

如果需要,唯一的补充是标记 WMI 查询失败的机器,以便技术人员在需要/需要时进一步跟进。

【讨论】:

    猜你喜欢
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多