自动化零信任设备健康检查

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
function Get-DeviceCompliance {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$ComputerName
)

# 验证TPM状态
$tpmStatus = Get-Tpm -ComputerName $ComputerName -ErrorAction SilentlyContinue
# 检查BitLocker加密状态
$bitlocker = Get-BitLockerVolume -MountPoint $env:SystemDrive -ErrorAction SilentlyContinue
# 获取防病毒状态
$avStatus = Get-MpComputerStatus -ErrorAction SilentlyContinue

[PSCustomObject]@{
ComputerName = $ComputerName
TPMEnabled = $tpmStatus.TpmPresent
SecureBoot = (Confirm-SecureBootUEFI).SecureBootEnabled
BitLockerStatus = $bitlocker.VolumeStatus
AntivirusEnabled = $avStatus.AMServiceEnabled
LastUpdate = (Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 1).InstalledOn
}
}

# 执行企业终端健康检查
$devices = 'PC001','PC002','PC003'
$report = $devices | ForEach-Object {
Get-DeviceCompliance -ComputerName $_ -Verbose
}

# 生成合规性报告
$report | Export-Csv -Path "ZeroTrust_Compliance_Report_$(Get-Date -Format yyyyMMdd).csv" -NoTypeInformation

本脚本实现以下零信任核心检查项:

  1. TPM芯片启用状态验证
  2. Secure Boot安全启动配置
  3. 系统盘BitLocker加密状态
  4. 防病毒实时监控状态
  5. 系统最后更新日期

扩展建议:

  • 与Azure AD条件访问策略集成
  • 添加自动修复功能
  • 实现实时监控告警机制

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
43
44
45
46
47
48
49
50
51
function Invoke-DeviceHealthCheck {
[CmdletBinding()]
param(
[ValidateSet('Basic','Full')]
[string]$ScanLevel = 'Basic'
)

$healthReport = [PSCustomObject]@{
Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
DeviceID = (Get-CimInstance -ClassName Win32_ComputerSystem).Name
Compliance = $true
SecurityScore = 100
Findings = @()
}

# 基础检查项
$checks = @(
{ Get-CimInstance -ClassName Win32_BIOS | Select-Object Version,ReleaseDate },
{ Get-WindowsUpdateLog -Last 7 | Where Status -ne 'Installed' },
{ Get-NetFirewallProfile | Where Enabled -eq $false }
)

if ($ScanLevel -eq 'Full') {
$checks += @(
{ Get-Service -Name WinDefend | Where Status -ne 'Running' },
{ Get-ChildItem 'C:\Temp' -Recurse -File | Where {$_.LastWriteTime -gt (Get-Date).AddDays(-1)} },
{ Get-LocalUser | Where PasswordNeverExpires -eq $true }
)
}

foreach ($check in $checks) {
try {
$result = & $check
if ($result) {
$healthReport.Findings += [PSCustomObject]@{
CheckName = $check.ToString().Split('{')[1].Trim()
Status = 'NonCompliant'
Details = $result | ConvertTo-Json -Compress
}
$healthReport.SecurityScore -= 10
$healthReport.Compliance = $false
}
}
catch {
Write-Warning "检查项执行失败: $_"
}
}

$healthReport | Export-Clixml -Path "$env:TEMP\DeviceHealthReport_$(Get-Date -Format yyyyMMdd).xml"
return $healthReport
}

核心功能

  1. 多层级设备健康扫描(基础/完整模式)
  2. 实时安全态势评分机制
  3. 自动化合规性验证
  4. XML格式审计报告生成

典型应用场景

  • 企业设备入网前合规检查
  • 零信任架构下的持续设备验证
  • 远程办公终端安全审计
  • 安全基线的快速验证