Skip to content

Instantly share code, notes, and snippets.

Get-ChildItem -File | ForEach-Object { if ($_.Name -match '^(\d{2})\.(\d{2})\.(\d{4})\s+(.+)$') { $n = "$($matches[3])-$($matches[2])-$($matches[1]) $($matches[4])"; if (-not (Test-Path $n)) { Rename-Item -Path $_.FullName -NewName $n; Write-Host "✓ $($_.Name) -> $n" -ForegroundColor Green } } }
function NormalizeNonBreakingSpaceInBeck {
try {
$word = [Runtime.InteropServices.Marshal]::GetActiveObject("Word.Application")
} catch {
throw "Keine aktive Word-Instanz gefunden."
}
$doc = $word.ActiveDocument
$wdFindContinue = 1
$wdReplaceAll = 2
param (
[string]$FilePath,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Patterns
)
if (-not (Test-Path $FilePath)) {
Write-Error "'$FilePath' not found."
exit 1
}
@eugrus
eugrus / Extract-Audio.ps1
Created September 19, 2025 08:14
wrapper for ffmpeg
param([Parameter(Mandatory=$true)][string]$InputFile)
if (-not (Test-Path $InputFile)) { Write-Error "No '$InputFile'"; exit 1 }
ffmpeg -i "$InputFile" -vn -b:a 64k $("$( [System.IO.Path]::ChangeExtension($InputFile, '.mp3') )")
@eugrus
eugrus / lines.ps1
Last active September 16, 2025 09:07
basically grep -ni or findstr /N /I in PowerShell
param (
[string]$Pattern,
[string]$Path
)
if (-not (Test-Path $Path)) {
Write-Error "File '$Path' not found."
exit 1
}
gc $env:USERPROFILE\.ssh\id_ed25519.pub | ssh $args[0] "cat >> .ssh/authorized_keys"
param (
[string]$Query
)
$apiKey = "" # https://console.cloud.google.com/apis/credentials
$cseId = "" # https://programmablesearchengine.google.com/
$results = @()
$encodedQuery = [System.Uri]::EscapeDataString($Query)
@eugrus
eugrus / Copy-AllStyles.ps1
Last active September 9, 2025 16:52
Copying Word styles between documents
#Requires -Version 5.1
<#
.SYNOPSIS
Копирует все стили из одного документа Word в другой.
.DESCRIPTION
Этот скрипт открывает два документа Word: документ-донор и целевой документ.
Затем он копирует все стили из донора в целевой документ, перезаписывая существующие стили с теми же именами.
Для работы скрипта требуется, чтобы на компьютере был установлен Microsoft Word.
.PARAMETER SourcePath
Обязательный. Укажите путь к документу Word, из которого нужно скопировать стили (донор).
@eugrus
eugrus / NoColor.ps1
Created September 3, 2025 11:56
remove highlights & shading from the active document in Word
$word = [Runtime.Interopservices.Marshal]::GetActiveObject("Word.Application")
$doc = $word.ActiveDocument
if ($doc) {
# Clear highlights & shading
foreach ($r in $doc.StoryRanges) {
do {
$r.HighlightColorIndex = [Microsoft.Office.Interop.Word.WdColorIndex]::wdNoHighlight
$r.Shading.BackgroundPatternColor = [Microsoft.Office.Interop.Word.WdColor]::wdColorAutomatic
$r = $r.NextStoryRange
} while ($r)
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Screen]::PrimaryScreen.Bounds