For those of us insignificant enough to have our own thread. A place to be a professional noob. Take a script, leave a script. Discuss stuff or things Give credit where it's due.
After amassing a pile of unholy .regs, slowly adding values all around as I worked towards the "perfect image," I knew there were plenty of duplicate keys and values. Thus I eventually got around to making this script. Reg file combiners seem to forget the step that is checking for duplication. This powershell module will combine duplicate keys and remove their duplicate values, handling multi-line values and removing extra blank lines, while alphabetizing by key. In the future, I may add multi-.reg processing and a simple GUI. Clean-Regfile -in (path to .reg) -out (path to clean .reg) Spoiler: clean-regfile.psm1 Code: # Removes duplicate blanks, keys, and single- or multi-line values, combining and alphabetizing them. function Clean-Regfile { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [ValidateScript({ if (Test-Path $_ -PathType Leaf) { if ($_ -match "\.reg$") { $true } else { throw "The input file must be a .reg file." } } else { throw "The specified input file does not exist." } })] [string]$in, [Parameter(Mandatory = $true)] [string]$out ) # Read the input .reg file $lines = Get-Content -Path $in # Remove lines starting with "Windows Registry Editor" $lines = $lines | Where-Object { -not $_.StartsWith("Windows Registry Editor") } # Variables to track the current key block and its values $keyBlocks = @{} $currentKey = $null $currentBlock = @() foreach ($line in $lines) { if ($line -match '^\[.*\]$') { # If we encounter a new key block start if ($currentKey -ne $null) { # Store the previous key block if (-not $keyBlocks.ContainsKey($currentKey)) { $keyBlocks[$currentKey] = @() } $keyBlocks[$currentKey] += $currentBlock } # Start a new key block $currentKey = $line $currentBlock = @() } else { # Add the line to the current key block $currentBlock += $line } } # Don't forget to add the last key block if ($currentKey -ne $null) { if (-not $keyBlocks.ContainsKey($currentKey)) { $keyBlocks[$currentKey] = @() } $keyBlocks[$currentKey] += $currentBlock } # Process each key block to remove duplicate lines and reduce multiple blank lines to one $cleanedBlocks = @{} foreach ($key in $keyBlocks.Keys) { $uniqueLines = @() $seenLines = @{} $blankLineCount = 0 foreach ($block in $keyBlocks[$key]) { foreach ($line in $block) { if ($line -eq "") { $blankLineCount++ if ($blankLineCount -eq 1) { $uniqueLines += $line } } else { $blankLineCount = 0 if (-not $seenLines.ContainsKey($line)) { $uniqueLines += $line $seenLines[$line] = $true } } } } $cleanedBlocks[$key] = $uniqueLines } # Add the "Windows Registry Editor Version 5.00" line and a blank line at the beginning $outputLines = @("Windows Registry Editor Version 5.00", "") # Write the cleaned data to the output file foreach ($key in $cleanedBlocks.Keys | Sort-Object) { $outputLines += "" $outputLines += $key $outputLines += $cleanedBlocks[$key] } # Convert $outputLines to $cleanLines, scan for instances of more than one blank line, and remove the extras $cleanLines = @() $blankLineCount = 0 foreach ($line in $outputLines) { if ($line -eq "") { $blankLineCount++ if ($blankLineCount -eq 1) { $cleanLines += $line } } else { $blankLineCount = 0 $cleanLines += $line } } # Copy $cleanLines back to $outputLines $outputLines = $cleanLines # Output the file $outputLines | Set-Content -Path $out } Export-ModuleMember -Function Clean-Regfile #githubgist
Let's discuss about life most of the time, I watch music, & not write any s**t. and at my work, i do work on things that might relate to computer, SAP and when i don't, i help with electricity & lifting sides fixes, or fix computer, not hardware. cause' coding is boring. i can't \ will not do coding all my life. what is sap. good question.
Music is always good. I found some great artists on sound.xyz, funding their underground by buying NFTs of their tracks. Sure the NFT might not be worth what I pay but helping a pro noob make it towards the big leagues is a good investment. Where you can't do, use an AI. Could hire 4 fools and get almost twice as much done for the cost of one pro. Visual Studio Enterprise practically codes for you if you already have working code. Deepseek Coder V2 can generate that code with the right prompts. Only reason I started to learn was because I was tired of not having "an app for that" and being greatly displeased with the state of GUIs. Have another powershell script. Write-Human. It simulates human typing, and can alternate the color of the letters/words it types using -mode disco/discoword. Edit the Start-sleep line near the end to make it take longer to type. I had mine set up to start with "(blank, 3s delay) The matrix has you..." for a while. Credit to markwragg on github. Spoiler: write-human Function Write-Human { <# .SYNOPSIS Use to output text as if typed by a human. .SYNOPSIS This script takes one or more strings and prints them to the screen with a slightly randomised delay between each character to emulate a human typing. .EXAMPLE Get-Content .\mytestfile.txt | Write-Human #> [cmdletbinding()] Param( [parameter(ValueFromPipeline)] [string] $InputObject, [int] $Speed = 1, [ValidateSet('Disco','DiscoWord', 'Terminal')] [string] $Mode ) Begin { if ($Mode -eq 'Terminal') { $console = $host.ui.rawui $console.backgroundcolor = "black" Clear-Host } } Process { $InputObject -Split "`n" | ForEach-Object { $FGColor = (7..15 | Get-Random) ForEach ($Char in $_.ToCharArray()) { Switch ($Mode) { 'Disco' { Write-Host $Char -NoNewLine -ForegroundColor (7..15 | Get-Random) } 'DiscoWord' { Write-Host $Char -NoNewLine -ForegroundColor $FGColor if ($Char -eq ' ') { $FGColor = (7..15 | Get-Random) } } 'Terminal' { Write-Host $Char -NoNewLine -ForegroundColor Green -BackgroundColor Black } default { Write-Host $Char -NoNewLine } } Start-Sleep -Milliseconds (Get-Random -Min (10 / $Speed) -Max (100 / $Speed)) } Write-Host } } }