PowerShell 技能连载 - 零信任架构下的设备健康检查
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| function Invoke-DeviceHealthCheck { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$DeviceName )
$healthReport = [PSCustomObject]@{ Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' Device = $DeviceName TPMEnabled = $false SecureBoot = $false AntivirusStatus = 'Unknown' ComplianceScore = 0 }
try { $tpm = Get-Tpm -ErrorAction Stop $healthReport.TPMEnabled = $tpm.TpmPresent
$healthReport.SecureBoot = Confirm-SecureBootUEFI
$avStatus = Get-MpComputerStatus $healthReport.AntivirusStatus = $avStatus.AMServiceEnabled ? 'Active' : 'Inactive'
$compliance = 0 if($healthReport.TPMEnabled) { $compliance += 30 } if($healthReport.SecureBoot) { $compliance += 30 } if($healthReport.AntivirusStatus -eq 'Active') { $compliance += 40 } $healthReport.ComplianceScore = $compliance } catch { Write-Warning "设备健康检查失败: $_" }
$healthReport | Export-Clixml -Path "$env:TEMP/DeviceHealth_$DeviceName.xml" return $healthReport }
|
核心功能:
- TPM芯片状态验证
- 安全启动模式检测
- 反病毒服务状态监控
- 自动化合规评分
应用场景:
- 零信任架构准入控制
- 远程办公设备安全审计
- 合规性基线验证
- 安全事件响应前置检查