[英]Checking Windows Disk Encryption with Pester
我正在尝试使用以下 Pester 代码使用 Pester 测试 Windows Server 上本地磁盘的保护状态:
Describe 'Encryption Check' {
$Diskencr = Get-BitLockerVolume
$Diskencr.ForEach{
write-host $_.ProtectionStatus
Context "Testing encryption on $($_)" {
It "Encryption Enabled?" {$_.ProtectionStatus -match 'On' | Should -Be $True}
}
}
}
输出显示 3 个磁盘的“保护状态”打开,1 个关闭。
但是Pester“It check”说所有都是假的,我不知道为什么?
Starting discovery in 1 files.
Discovering in D:\Temp\test.ps1.
On
Off
On
On
Found 4 tests. 2.44s
Discovery finished in 2.44s.
Running tests from 'D:\Temp\test.ps1'
Describing Encryption Check
Context Testing encryption on E:
[-] Encryption Enabled? 15ms (14ms|1ms)
Expected $true, but got $false.
at It "Encryption Enabled?" {$_.ProtectionStatus -match 'On' | Should -Be $True}, D:\Temp\test.ps1:7
at <ScriptBlock>, D:\Temp\test.ps1:7
Context Testing encryption on \\?\Volume{070ba12e-0000-0000-0000-100000000000}\
[-] Encryption Enabled? 5ms (4ms|1ms)
Expected $true, but got $false.
at It "Encryption Enabled?" {$_.ProtectionStatus -match 'On' | Should -Be $True}, D:\Temp\test.ps1:7
at <ScriptBlock>, D:\Temp\test.ps1:7
Context Testing encryption on D:
[-] Encryption Enabled? 8ms (6ms|2ms)
Expected $true, but got $false.
at It "Encryption Enabled?" {$_.ProtectionStatus -match 'On' | Should -Be $True}, D:\Temp\test.ps1:7
at <ScriptBlock>, D:\Temp\test.ps1:7
Context Testing encryption on C:
[-] Encryption Enabled? 5ms (4ms|1ms)
Expected $true, but got $false.
at It "Encryption Enabled?" {$_.ProtectionStatus -match 'On' | Should -Be $True}, D:\Temp\test.ps1:7
at <ScriptBlock>, D:\Temp\test.ps1:7
Tests completed in 2.72s
Tests Passed: 0, Failed: 4, Skipped: 0 NotRun: 0
It块不允许范围渗入其中。 必须使用 -TestCases 参数将其重组为这样的内容
Describe 'Encryption Check' {
Context "Testing encryption on drives" {
It "checking a drive" -TestCases @(
$Diskencr = Get-BitLockerVolume
$Diskencr.ForEach{
@{ DriveLetter = $_ }
}
) {
param($DriveLetter)
Write-Host $DriveLetter
$DriveLetter.ProtectionStatus -match 'On' | Should -BeExactly $True
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.