Cmdlets/Find-Know.ps1
# ? TITEL Find-Know # ? DESCRIPTION Wissen in dieser PowerShell-Datenbank finden # ? TAGS Wissen PowerShell # ? VERSION 2019.10.20 function Find-Know { <# .SYNOPSIS Wissen in dieser PowerShell-Datenbank finden .PARAMETER Keyword Ein oder mehrere Keywords die im Titel, der Beschreibung, der Tags und im Inhalt (s. -IncludeContent) gesucht wird. .PARAMETER IncludeContent Bei der Suche wird der Inhalt einbezogen. #> [Alias("fk")] param ( [string[]]$Keyword, [switch]$IncludeContent ) Get-ChildItem -Path "." -Recurse -Include "*.ps1", "*.psm1", "*.psd1", "*.md" | Where-Object -Property FullName -NotMatch -Value "Einarbeiten" -PipelineVariable file | Get-Content -Encoding UTF8 -TotalCount 4 -ReadCount 4 | ForEach-Object -ErrorAction Stop -Process { if($_[0] -notmatch "TITEL" -or $_[1] -notmatch "DESCRIPTION" -or $_[2] -notmatch "TAGS" -or $_[3] -notmatch "VERSION") { "Die Datei $($file.FullName) enthält keinen korrekten Prolog" | Write-Warning return } [PSCustomObject]@{ Titel = [String]($_[0] -cReplace "^(?'Key'^#\s\?\s*TITEL\s)" , [string]::Empty) Beschreibung = [String]($_[1] -cReplace "^(?'Key'^#\s\?\s*DESCRIPTION\s)" , [string]::Empty) Tags = [String[]](($_[2] -cReplace "^(?'Key'^#\s\?\s*TAGS\s)" , [string]::Empty) -split ' ') Version = [Version]($_[3] -cReplace "^(?'Key'^#\s\?\s*VERSION\s)" , [string]::Empty) FileName = [String]$file.Name } } | Where-Object -FilterScript { $pattern = "($($Keyword -join "|"))" $_.Titel -IMatch $pattern ` -or $_.Beschreibung -IMatch $pattern ` -or ($_.Tags -join ";") -IMatch $pattern ` -or $_.FileName -IMatch $pattern ` -or ($IncludeContent -and ($file | Select-String -Pattern $pattern -Quiet)) } } New-Alias -Name fk -Value Find-Know -Force |