[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Pattern, [string]$Root = 'HKCU:\Software', [ValidateRange(1, 5000)] [int]$MaxResults = 200, [string]$Csv ) $ErrorActionPreference = 'Stop' if (-not (Test-Path -LiteralPath $Root)) { throw "Ветка реестра не найдена: $Root" } $results = New-Object System.Collections.Generic.List[object] try { $items = @(Get-Item -LiteralPath $Root -ErrorAction Stop) + @(Get-ChildItem -LiteralPath $Root -Recurse -ErrorAction SilentlyContinue) } catch { throw "Не удалось прочитать ветку ${Root}: $_" } foreach ($key in $items) { if ($results.Count -ge $MaxResults) { break } if ($key.PSChildName -like "*$Pattern*" -or $key.Name -like "*$Pattern*") { $results.Add([pscustomobject]@{ Type = 'Key'; Path = $key.Name; Name = $key.PSChildName; Value = '' }) } $props = Get-ItemProperty -LiteralPath $key.PSPath -ErrorAction SilentlyContinue if ($null -eq $props) { continue } foreach ($prop in $props.PSObject.Properties) { if ($prop.Name -like 'PS*') { continue } if ($results.Count -ge $MaxResults) { break } $valueText = '' try { $valueText = [string]$prop.Value } catch { $valueText = '' } if ($prop.Name -like "*$Pattern*" -or $valueText -like "*$Pattern*") { $results.Add([pscustomobject]@{ Type = 'Value'; Path = $key.Name; Name = $prop.Name; Value = $valueText }) } } } Write-Host ("Найдено результатов: {0}" -f $results.Count) if ($results.Count -gt 0) { $results | Format-Table -AutoSize -Wrap } if ($Csv) { $parent = Split-Path -Parent $Csv if ($parent -and -not (Test-Path -LiteralPath $parent)) { New-Item -ItemType Directory -Path $parent | Out-Null } $results | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "Результаты сохранены: $Csv" } if ($results.Count -ge $MaxResults) { Write-Host "Достигнут лимит $MaxResults. Увеличьте -MaxResults или сузьте ветку поиска." }