# Module ZipBuilder - Creation ZIP en memoire pour envoi config Enocean Add-Type -AssemblyName System.IO.Compression function New-EnoceanZip { [CmdletBinding()] param( [Parameter(Mandatory)] [hashtable[]]$XmlFiles # Chaque hashtable : @{ Name = "enoceandevice1.xml"; Content = "..." } ) $memoryStream = New-Object System.IO.MemoryStream # leaveOpen = $true pour pouvoir lire le stream apres fermeture de l'archive $archive = New-Object System.IO.Compression.ZipArchive($memoryStream, [System.IO.Compression.ZipArchiveMode]::Create, $true) foreach ($xmlFile in $XmlFiles) { # Chemin interne avec forward slashes $entryPath = "enocean/configuration/devices/$($xmlFile.Name)" $entry = $archive.CreateEntry($entryPath, [System.IO.Compression.CompressionLevel]::Optimal) $entryStream = $entry.Open() $writer = New-Object System.IO.StreamWriter($entryStream, [System.Text.Encoding]::UTF8) $writer.Write($xmlFile.Content) $writer.Flush() $writer.Close() $entryStream.Close() } $archive.Dispose() $zipBytes = $memoryStream.ToArray() $memoryStream.Close() Write-Log -Message "ZIP cree en memoire : $($XmlFiles.Count) fichier(s), $($zipBytes.Length) octets" -Level INFO return $zipBytes } function Get-ZipFilename { [CmdletBinding()] param( [Parameter(Mandatory)] [byte[]]$ZipBytes ) $md5 = [System.Security.Cryptography.MD5]::Create() $hashBytes = $md5.ComputeHash($ZipBytes) $hashString = ($hashBytes | ForEach-Object { $_.ToString("x2") }) -join "" return "fullConfig.$hashString.zip" } Export-ModuleMember -Function New-EnoceanZip, Get-ZipFilename