| 12
 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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 
 | function Invoke-DeviceHealthCheck {[CmdletBinding()]
 param(
 [Parameter(Mandatory=$true)]
 [string]$DeviceName,
 
 [ValidateSet('Basic','Full')]
 [string]$ScanMode = 'Basic'
 )
 
 $complianceReport = [PSCustomObject]@{
 Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
 DeviceName = $DeviceName
 EncryptionStatus = $null
 PatchLevel = $null
 FirewallRules = @()
 ComplianceScore = 0
 }
 
 try {
 
 $encryptionStatus = Get-BitLockerVolume -MountPoint C: |
 Select-Object -ExpandProperty EncryptionPercentage
 $complianceReport.EncryptionStatus = $encryptionStatus -ge 100 ? 'Compliant' : 'Non-Compliant'
 
 
 $updates = Get-HotFix |
 Where-Object InstalledOn -lt (Get-Date).AddDays(-30)
 $complianceReport.PatchLevel = $updates.Count -eq 0 ? 'Current' : 'Outdated'
 
 
 if ($ScanMode -eq 'Full') {
 $firewallRules = Get-NetFirewallRule |
 Where-Object Enabled -eq True |
 Select-Object DisplayName, Direction, Action
 $complianceReport.FirewallRules = $firewallRules
 }
 
 
 $score = 0
 if ($complianceReport.EncryptionStatus -eq 'Compliant') { $score += 40 }
 if ($complianceReport.PatchLevel -eq 'Current') { $score += 30 }
 if ($complianceReport.FirewallRules.Count -eq 0) { $score += 30 }
 $complianceReport.ComplianceScore = $score
 }
 catch {
 Write-Error "设备健康检查失败: $_"
 }
 
 
 $complianceReport | Export-Clixml -Path "$env:TEMP/${DeviceName}_ComplianceReport_$(Get-Date -Format yyyyMMdd).xml"
 return $complianceReport
 }
 
 |