| 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
 54
 
 | function Invoke-AILogAnalysis {[CmdletBinding()]
 param(
 [Parameter(Mandatory=$true)]
 [string]$LogPath,
 
 [ValidateSet('Classification','Anomaly')]
 [string]$AnalysisType = 'Classification'
 )
 
 $analysisReport = [PSCustomObject]@{
 Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
 TotalEntries = 0
 DetectedPatterns = @()
 ModelAccuracy = 0
 }
 
 try {
 
 $model = Import-MLModel -Path "$PSScriptRoot/log_analysis_model.zip"
 
 
 $logData = Get-Content $LogPath |
 ConvertFrom-LogEntry -ErrorAction Stop |
 Select-Object TimeGenerated, Message, Level
 
 $analysisReport.TotalEntries = $logData.Count
 
 
 $predictions = switch($AnalysisType) {
 'Classification' {
 $logData | Invoke-MLClassification -Model $model
 }
 'Anomaly' {
 $logData | Invoke-MLAnomalyDetection -Model $model
 }
 }
 
 
 $analysisReport.DetectedPatterns = $predictions |
 Where-Object { $_.Probability -gt 0.7 } |
 Select-Object LogMessage, PatternType, Probability
 
 
 $analysisReport.ModelAccuracy = ($predictions.ValidationScore | Measure-Object -Average).Average
 }
 catch {
 Write-Error "日志分析失败: $_"
 }
 
 
 $analysisReport | Export-Csv -Path "$env:TEMP/AILogReport_$(Get-Date -Format yyyyMMdd).csv"
 return $analysisReport
 }
 
 |