PowerShell SecureBoot检测脚本
我正在尝试确定SecureBoot是否已启用或未使用PowerShell。 到目前为止,该值设置为Enabled,但是我的检测脚本始终显示Disabled。 我可能做错了,但我很接近,我想是的,请看一下我的剧本,让我知道我做错了什么PowerShell SecureBoot检测脚本,powershell,Powershell,我正在尝试确定SecureBoot是否已启用或未使用PowerShell。 到目前为止,该值设置为Enabled,但是我的检测脚本始终显示Disabled。 我可能做错了,但我很接近,我想是的,请看一下我的剧本,让我知道我做错了什么 #Install module Get-BIOS if not already installed if (Get-Module -ListAvailable -Name GetBIOS) { Write-Host "Module exists&q
#Install module Get-BIOS if not already installed
if (Get-Module -ListAvailable -Name GetBIOS) {
Write-Host "Module exists"
}
else {
Install-Module -Name GetBIOS -Repository PSGallery -Force
}
#Set variable $SecureBoot
[String]$SecureBoot = (Get-Bios | Select-Object -Property Setting,Value | Where-Object {$_.Setting -eq "SecureBoot"})
try {
if ($SecureBoot -eq "Enabled") {
Write-Output "Secure Boot is Enabled"; exit 1
} else {
Write-Output "Secure Boot is Disabled"; exit 0
}
} catch {
Write-Output "Issues occured while attempting to detect $SecureBoot : $($_.Exception.Message)"; exit 1
}
提前多谢 继续我的评论: 使用
Select Object-Property设置,Value
可以检索具有这两个属性的对象,而不是字符串,因此
删除对[string]
的强制转换,并在测试中使用.Value
属性:
$SecureBoot = (Get-Bios | Select-Object -Property Setting,Value | Where-Object {$_.Setting -eq "SecureBoot"})
try {
if ($SecureBoot.Value -eq "Enabled") {
Write-Output "Secure Boot is Enabled"; exit 1
} else {
Write-Output "Secure Boot is Disabled"; exit 0
}
} catch {
Write-Output "Issues occured while attempting to detect SecureBoot : $($_.Exception.Message)"; exit 1
}
或
仅捕获$SecureBoot中的.Value
属性
$SecureBoot = (Get-Bios | Select-Object -Property Setting,Value | Where-Object {$_.Setting -eq "SecureBoot"}).Value
try {
if ($SecureBoot -eq "Enabled") {
Write-Output "Secure Boot is Enabled"; exit 1
} else {
Write-Output "Secure Boot is Disabled"; exit 0
}
} catch {
Write-Output "Issues occured while attempting to detect SecureBoot : $($_.Exception.Message)"; exit 1
}
您的变量
$SecureBoot
不是字符串,但由于您在Select对象中指定了两个属性,因此这是一个具有两个属性的对象。删除对[string]
的强制转换,并在($SecureBoot.Value-eq“Enabled”)的情况下尝试