<# ECRE Migrate: Windows inventory collector (version 1). Lists the certificates in the Windows certificate stores, the key exchange groups enabled for Windows TLS (Schannel), and the OpenSSH server settings, and writes them to one JSON file. Check that file at https://ecreqc.com/migrate/ (it is read inside your browser) or with "ecre-pq migrate scan". It only reads. It never exports a private key, needs no password, changes nothing and sends nothing over the network. Run it as administrator to include the computer's own SSH settings. Usage: powershell -NoProfile -ExecutionPolicy Bypass -File ecre-migrate-windows.ps1 [-Out ] #> param([string]$Out = (Join-Path ([Environment]::GetFolderPath('Desktop')) 'ecre-windows-inventory.json')) Set-StrictMode -Version 2 $ErrorActionPreference = 'Stop' # Certificate stores, read through .NET (works whatever PowerShell modules are loaded). $X509 = 'System.Security.Cryptography.X509Certificates' $storeNames = @('My', 'Root', 'AuthRoot', 'CA', 'TrustedPeople', 'TrustedPublisher', 'Disallowed', 'AddressBook', 'WebHosting', 'Remote Desktop', 'TrustedDevices', 'ClientAuthIssuer', 'SmartCardRoot', 'Homegroup Machine Certificates') $certs = New-Object System.Collections.ArrayList foreach ($loc in 'LocalMachine', 'CurrentUser') { foreach ($name in $storeNames) { $store = $null try { $store = New-Object "$X509.X509Store" -ArgumentList $name, ([Enum]::Parse([type]"$X509.StoreLocation", $loc)) $store.Open([Enum]::Parse([type]"$X509.OpenFlags", 'ReadOnly, OpenExistingOnly')) foreach ($c in $store.Certificates) { [void]$certs.Add([ordered]@{ store = "$loc\$name" thumbprint = [string]$c.Thumbprint has_private_key = [bool]$c.HasPrivateKey der = [Convert]::ToBase64String($c.RawData) }) } } catch { } finally { if ($store) { $store.Close() } } } } # Key exchange groups of Windows TLS: group policy ("ECC Curve Order") wins over the default list. $groups = @() $source = 'none' try { $groups = @(Get-TlsEccCurve -ErrorAction Stop | ForEach-Object { [string]$_ }); $source = 'Get-TlsEccCurve' } catch { } try { $policy = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002' -Name EccCurves -ErrorAction Stop if ($policy.EccCurves) { $groups = @($policy.EccCurves | ForEach-Object { [string]$_ }); $source = 'group policy' } } catch { } # OpenSSH server settings and the administrators' authorised keys, when present and readable. $files = New-Object System.Collections.ArrayList foreach ($f in @("$env:ProgramData\ssh\sshd_config", "$env:ProgramData\ssh\administrators_authorized_keys")) { try { if (Test-Path -LiteralPath $f -PathType Leaf) { $bytes = [IO.File]::ReadAllBytes($f) if ($bytes.Length -le 1MB) { [void]$files.Add([ordered]@{ path = $f; data = [Convert]::ToBase64String($bytes) }) } } } catch { } } $report = [ordered]@{ type = 'ecre-migrate-windows-v1' tool = 'ecre-migrate-windows.ps1 1' created = (Get-Date).ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss'Z'") computer = [string]$env:COMPUTERNAME os = [Environment]::OSVersion.VersionString tls_groups = @($groups) tls_groups_source = $source certificates = @($certs.ToArray()) files = @($files.ToArray()) } $json = ConvertTo-Json -InputObject $report -Depth 5 -Compress [IO.File]::WriteAllText($Out, $json, (New-Object System.Text.UTF8Encoding $false)) Write-Host "ECRE Migrate: wrote $Out ($($certs.Count) certificates). Check it at https://ecreqc.com/migrate/ or with: ecre-pq migrate scan `"$Out`""