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 }
|