使用Pester测试PowerShell AMSI

使用Pester测试PowerShell AMSI,powershell,pester,Powershell,Pester,我正在写一个Pester测试来验证Windows计算机的配置。我需要的测试之一是验证PowerShell AMSI是否正常工作 有一个AMSI测试字符串可用于验证函数。我创建了以下测试 It '"Antimalware Scan Interface" is working' { # AMSI test string 'AMSI Test Sample: 7e72c3ce-861b-4339-8740-0ac1484c1386' # (in the following as an

我正在写一个Pester测试来验证Windows计算机的配置。我需要的测试之一是验证PowerShell AMSI是否正常工作

有一个AMSI测试字符串可用于验证函数。我创建了以下测试

It '"Antimalware Scan Interface" is working' {
    # AMSI test string 'AMSI Test Sample: 7e72c3ce-861b-4339-8740-0ac1484c1386'
    # (in the following as an obfuscated string)
    # must throw an error if executed (blocked by AMSI)
    $TestString = "FHJ+YHoTZ1ZARxNgUl5DX1YJEwRWBAFQAFBWHgsFAlEeBwAACh4LBAcDHgNSUAIHCwdQAgALBRQ="
    $Bytes = [Convert]::FromBase64String($TestString)
    $String = -join ($bytes | ForEach-Object { [char]($_ -bxor 0x33)})
    { Invoke-Expression -Command $String } | Should Throw
}
如果我运行测试,AMSI工作得很好,以至于没有执行完整的上下文块,即测试没有执行,也没有报告成功

我在Filename.Tests.ps1:420字符:36+上下文“配置PowerShell”{+~脚本包含恶意数据,被反恶意软件阻止。(翻译文本。原文可能略有不同。)

相反,我希望执行上下文并返回一个抛出错误的“testsuccessful”


你知道我如何处理这个问题或者测试AMSI吗?

我不确定你是否能够解决这个问题,因为AMSI正在做它的工作。出于好奇,使用
启动进程而不是调用表达式帮助吗?如果你的意思是像
。powershell.exe-command$command
-它没有:/我不确定你是不是我们将能够解决这一问题,因为AMSI正在做它的工作。出于好奇,使用
启动流程
而不是调用表达式帮助吗?如果您的意思是像
.powershell.exe-command$command
,它不会:/