# BAOI Diagnostic Collector 1.0.2 # Boite a Outils Informatique - lecture seule # Compatible Windows PowerShell 5.1+ # Ce script ne modifie aucun parametre systeme. Il collecte des informations de diagnostic # puis cree un package baoi-diagnostic-package/1.0 localement. [CmdletBinding()] param( [string]$OutputDirectory = "$env:USERPROFILE\Desktop" ) $ErrorActionPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue' $now = Get-Date $packageId = [guid]::NewGuid().ToString() $work = Join-Path $env:TEMP ("BAOI-Diagnostic-" + $packageId) New-Item -ItemType Directory -Path $work -Force | Out-Null function Safe-Value($ScriptBlock) { try { & $ScriptBlock } catch { $null } } $os = Safe-Value { Get-CimInstance Win32_OperatingSystem } $cs = Safe-Value { Get-CimInstance Win32_ComputerSystem } $bios = Safe-Value { Get-CimInstance Win32_BIOS } $csp = Safe-Value { Get-CimInstance Win32_ComputerSystemProduct } $cpu = Safe-Value { Get-CimInstance Win32_Processor | Select-Object -First 1 } $boot = if ($os) { $os.LastBootUpTime } else { $null } $uptimeHours = if ($boot) { [math]::Round(((Get-Date) - $boot).TotalHours, 1) } else { $null } $biosReleaseDate = if ($bios -and $bios.ReleaseDate) { Safe-Value { ([datetime]$bios.ReleaseDate).ToString('o') } } else { '' } $volumes = @() Safe-Value { Get-Volume | Where-Object { $_.DriveLetter } | ForEach-Object { $size = [double]$_.Size $free = [double]$_.SizeRemaining $script:volumes += [ordered]@{ drive = ($_.DriveLetter + ':') filesystem = [string]$_.FileSystem health = [string]$_.HealthStatus size_gb = if ($size -gt 0) { [math]::Round($size / 1GB, 2) } else { 0 } free_gb = if ($free -ge 0) { [math]::Round($free / 1GB, 2) } else { 0 } free_pct = if ($size -gt 0) { [math]::Round(($free / $size) * 100, 1) } else { $null } } } } $physicalDisks = @() if (Get-Command Get-PhysicalDisk -ErrorAction SilentlyContinue) { Safe-Value { Get-PhysicalDisk | ForEach-Object { $script:physicalDisks += [ordered]@{ name = [string]$_.FriendlyName serial_number = [string]$_.SerialNumber media_type = [string]$_.MediaType bus_type = [string]$_.BusType health = [string]$_.HealthStatus operational_status = [string](@($_.OperationalStatus) -join ', ') size_gb = if ([double]$_.Size -gt 0) { [math]::Round(([double]$_.Size / 1GB), 2) } else { 0 } } } } } if ($physicalDisks.Count -eq 0) { Safe-Value { Get-CimInstance Win32_DiskDrive | ForEach-Object { $script:physicalDisks += [ordered]@{ name = [string]$_.Model serial_number = [string]$_.SerialNumber media_type = [string]$_.MediaType bus_type = [string]$_.InterfaceType health = [string]$_.Status operational_status = [string]$_.Status size_gb = if ([double]$_.Size -gt 0) { [math]::Round(([double]$_.Size / 1GB), 2) } else { 0 } } } } } $adapters = @() $defaultGateway = $null Safe-Value { Get-NetIPConfiguration | Where-Object { $_.NetAdapter.Status -eq 'Up' } | ForEach-Object { $ipv4 = @($_.IPv4Address | ForEach-Object { $_.IPAddress }) $gateway = @($_.IPv4DefaultGateway | ForEach-Object { $_.NextHop }) $dns = @((Get-DnsClientServerAddress -InterfaceIndex $_.InterfaceIndex -AddressFamily IPv4).ServerAddresses) if (-not $defaultGateway -and $gateway.Count -gt 0) { $script:defaultGateway = [string]$gateway[0] } $script:adapters += [ordered]@{ name = [string]$_.InterfaceAlias description = [string]$_.NetAdapter.InterfaceDescription status = [string]$_.NetAdapter.Status link_speed = [string]$_.NetAdapter.LinkSpeed ipv4 = $ipv4 gateway = $gateway dns = $dns dhcp = [string]$_.NetIPv4Interface.Dhcp } } } $gatewayReachable = $null if ($defaultGateway) { $gatewayReachable = [bool](Safe-Value { Test-Connection -ComputerName $defaultGateway -Count 1 -Quiet }) } $internet443 = $false $internetTest = Safe-Value { Test-NetConnection -ComputerName '1.1.1.1' -Port 443 -WarningAction SilentlyContinue } if ($internetTest) { $internet443 = [bool]$internetTest.TcpTestSucceeded } $dnsResolution = $false $dnsResult = Safe-Value { Resolve-DnsName -Name 'boiteaoutilsinformatique.fr' -Type A -ErrorAction Stop } if ($dnsResult) { $dnsResolution = $true } $services = @() foreach ($svcName in @('Dnscache','Dhcp','EventLog','Winmgmt','wuauserv')) { $svc = Safe-Value { Get-Service -Name $svcName } if ($svc) { $services += [ordered]@{ name = [string]$svc.Name; display_name = [string]$svc.DisplayName; status = [string]$svc.Status; start_type = [string]$svc.StartType } } } $eventItems = @() $criticalCount = 0 $errorCount = 0 $start = (Get-Date).AddHours(-24) foreach ($logName in @('System','Application')) { $events = Safe-Value { Get-WinEvent -FilterHashtable @{LogName=$logName; StartTime=$start; Level=1,2} -MaxEvents 60 } foreach ($evt in @($events)) { if ($evt.Level -eq 1) { $criticalCount++ } elseif ($evt.Level -eq 2) { $errorCount++ } $msg = [string]$evt.Message if ($msg.Length -gt 500) { $msg = $msg.Substring(0,500) } $eventItems += [ordered]@{ log = $logName id = [int]$evt.Id provider = [string]$evt.ProviderName time = $evt.TimeCreated.ToString('o') level = [string]$evt.LevelDisplayName message = $msg } } } $defender = $null if (Get-Command Get-MpComputerStatus -ErrorAction SilentlyContinue) { $mp = Safe-Value { Get-MpComputerStatus } if ($mp) { $defender = [ordered]@{ antivirus_enabled = [bool]$mp.AntivirusEnabled realtime_enabled = [bool]$mp.RealTimeProtectionEnabled signature_age_days = [int]$mp.AntivirusSignatureAge } } } $secureBoot = $null if (Get-Command Confirm-SecureBootUEFI -ErrorAction SilentlyContinue) { try { $secureBoot = [bool](Confirm-SecureBootUEFI -ErrorAction Stop) } catch { $secureBoot = $null } } $tpm = $null if (Get-Command Get-Tpm -ErrorAction SilentlyContinue) { $tpmRaw = Safe-Value { Get-Tpm } if ($tpmRaw) { $tpm = [ordered]@{ present = [bool]$tpmRaw.TpmPresent ready = [bool]$tpmRaw.TpmReady enabled = [bool]$tpmRaw.TpmEnabled activated = [bool]$tpmRaw.TpmActivated manufacturer_id = [string]$tpmRaw.ManufacturerIdTxt manufacturer_version = [string]$tpmRaw.ManufacturerVersion } } } $bitlocker = @() if (Get-Command Get-BitLockerVolume -ErrorAction SilentlyContinue) { Safe-Value { Get-BitLockerVolume | ForEach-Object { $script:bitlocker += [ordered]@{ mount_point = [string]$_.MountPoint volume_type = [string]$_.VolumeType volume_status = [string]$_.VolumeStatus protection_status = [string]$_.ProtectionStatus encryption_method = [string]$_.EncryptionMethod encryption_percentage = if ($null -ne $_.EncryptionPercentage) { [double]$_.EncryptionPercentage } else { $null } } } } } $hotfixes = @() Safe-Value { Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 20 | ForEach-Object { $script:hotfixes += [ordered]@{ id=[string]$_.HotFixID; installed_on=if ($_.InstalledOn) { $_.InstalledOn.ToString('yyyy-MM-dd') } else { '' } } } } $payload = [ordered]@{ schema = 'baoi-diagnostic-package/1.0' generated_at = $now.ToString('o') package_id = $packageId collector = [ordered]@{ name='BAOI Diagnostic Collector'; version='1.0.2'; mode='read-only'; source='boiteaoutilsinformatique.fr' } privacy = [ordered]@{ current_username_collected=$false; browser_history_collected=$false; passwords_collected=$false; documents_collected=$false } system = [ordered]@{ computer_name = [string]$env:COMPUTERNAME manufacturer = if ($cs) { [string]$cs.Manufacturer } else { '' } model = if ($cs) { [string]$cs.Model } else { '' } serial_number = if ($bios) { [string]$bios.SerialNumber } else { '' } hardware_uuid = if ($csp) { [string]$csp.UUID } else { '' } bios_version = if ($bios) { [string]$bios.SMBIOSBIOSVersion } else { '' } bios_release_date = if ($biosReleaseDate) { [string]$biosReleaseDate } else { '' } part_of_domain = if ($cs) { [bool]$cs.PartOfDomain } else { $false } domain_or_workgroup = if ($cs) { [string]$cs.Domain } else { '' } os_caption = if ($os) { [string]$os.Caption } else { '' } os_version = if ($os) { [string]$os.Version } else { '' } build_number = if ($os) { [string]$os.BuildNumber } else { '' } os_architecture = if ($os) { [string]$os.OSArchitecture } else { '' } last_boot = if ($boot) { $boot.ToString('o') } else { '' } uptime_hours = $uptimeHours memory_total_mb = if ($cs) { [math]::Round(([double]$cs.TotalPhysicalMemory / 1MB),0) } else { $null } memory_free_mb = if ($os) { [math]::Round(([double]$os.FreePhysicalMemory / 1024),0) } else { $null } } hardware = [ordered]@{ processor = if ($cpu) { [ordered]@{ name=[string]$cpu.Name; cores=[int]$cpu.NumberOfCores; logical_processors=[int]$cpu.NumberOfLogicalProcessors; max_clock_mhz=[int]$cpu.MaxClockSpeed } } else { $null } physical_disks = $physicalDisks } storage = $volumes network = [ordered]@{ adapters = $adapters default_gateway = $defaultGateway tests = [ordered]@{ gateway_reachable=$gatewayReachable; internet_tcp_443=$internet443; dns_resolution=$dnsResolution; dns_name='boiteaoutilsinformatique.fr' } } services = $services events = [ordered]@{ window_hours=24; critical=$criticalCount; error=$errorCount; items=$eventItems } security = [ordered]@{ defender=$defender; secure_boot=$secureBoot; tpm=$tpm; bitlocker=$bitlocker } hotfixes = $hotfixes } $jsonPath = Join-Path $work 'baoi-diagnostic.json' $json = $payload | ConvertTo-Json -Depth 10 $utf8NoBom = New-Object System.Text.UTF8Encoding($false) [System.IO.File]::WriteAllText($jsonPath, $json, $utf8NoBom) $stamp = Get-Date -Format 'yyyyMMdd-HHmmss' $zipPath = Join-Path $OutputDirectory ("BAOI-Diagnostic-" + $stamp + '.zip') if (Test-Path $zipPath) { Remove-Item $zipPath -Force } Compress-Archive -Path $jsonPath -DestinationPath $zipPath -CompressionLevel Optimal Remove-Item $work -Recurse -Force Write-Host '' Write-Host 'Diagnostic BAOI cree :' -ForegroundColor Green Write-Host $zipPath Write-Host '' Write-Host 'Importez ce ZIP dans BAOI Diagnostic Analyzer :' -ForegroundColor Cyan Write-Host 'https://boiteaoutilsinformatique.fr/diagnostic-analyzer/'