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
| # Dossier pour stocker les statistiques.
$StatsFolder = "C:\DNSStats"
if (-not (Test-Path $StatsFolder)) {
New-Item -ItemType Directory -Path $StatsFolder | Out-Null
}
# Fonction pour capturer les statistiques DNS
function Capture-DnsStatistics {
$currentStats = Get-DnsServerStatistics
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$statsFile = Join-Path -Path $StatsFolder -ChildPath "DNSStats_$timestamp.json"
$currentStats | ConvertTo-Json -Depth 10 | Set-Content -Path $statsFile
}
# Fonction pour calculer les différences
function Get-DnsStatisticsDifference {
param (
[string]$StartFile,
[string]$EndFile
)
$startStats = Get-Content -Path $StartFile | ConvertFrom-Json
$endStats = Get-Content -Path $EndFile | ConvertFrom-Json
# Calcul des différences pour chaque compteur
$diffStats = @{}
foreach ($category in $startStats.GetEnumerator()) {
if ($category.Value -is [System.Collections.Hashtable]) {
$diffStats[$category.Key] = @{}
foreach ($counter in $category.Value.GetEnumerator()) {
$diffStats[$category.Key][$counter.Key] = $endStats[$category.Key][$counter.Key] - $startStats[$category.Key][$counter.Key]
}
} else {
$diffStats[$category.Key] = $endStats[$category.Key] - $startStats[$category.Key]
}
}
return $diffStats
}
# Capturer les statistiques actuelles
Capture-DnsStatistics
# Exemple d'utilisation
# Pour comparer deux fichiers :
# Get-DnsStatisticsDifference -StartFile "chemin_du_fichier_debut.json" -EndFile "chemin_du_fichier_fin.json" |
Partager