Last active
August 28, 2024 08:01
-
-
Save markwragg/0e59148c8a6e7ac1fa0c669a63584474 to your computer and use it in GitHub Desktop.
A Powershell Module that includes a function for searching a CSV file which is a Glossary of terms and presents the results in a variety of formats.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .Synopsis | |
| Glossary Module | |
| .DESCRIPTION | |
| A Powershell Module that includes a function for searching a CSV file which is a Glossary of terms and presents the results in a variety of formats. | |
| .EXAMPLE | |
| Search-Glossary MyTerm | |
| .EXAMPLE | |
| Search-Glossary MyTerm -PassThru | Export-CSV MyTerms.csv | |
| #> | |
| Function Search-Glossary | |
| { | |
| [CmdletBinding()] | |
| Param | |
| ( | |
| $Term, | |
| [switch]$PassThru = $False | |
| ) | |
| Process{ | |
| $Matches = (Import-CSV "$PSScriptRoot\Glossary.csv") | Where-Object {$_.Term -like "$Term*"} | |
| If (($Matches | Measure-Object).Count -eq 1){ | |
| Write-Host "`n TERM" | |
| Write-Host "`t$($Matches.Term)`n" | |
| If ($Matches.Category){ | |
| Write-Host " CATEGORY" | |
| Write-Host "`t$($Matches.Category)`n" | |
| } | |
| If ($Matches.Description){ | |
| Write-Host " DESCRIPTION" | |
| Write-Host "$(wrapText($Matches.Description))`n" | |
| } | |
| If ($Matches.Link){ | |
| Write-Host " LINK" | |
| Write-Host "`t$($Matches.Link)`n" | |
| } | |
| }ElseIf(!$PassThru){ | |
| Return $Matches | FL | |
| }Else{ | |
| Return $Matches | |
| } | |
| } | |
| } | |
| Function wrapText( $text, $width=($host.UI.RawUI.BufferSize.Width-10) ) | |
| { | |
| $words = $text -split "\s+" | |
| $col = 0 | |
| Write-Host -NoNewline "`t" | |
| foreach ( $word in $words ) | |
| { | |
| $col += $word.Length + 1 | |
| if ( $col -gt $width ) | |
| { | |
| Write-Host "" | |
| $col = $word.Length + 1 | |
| Write-Host -NoNewline "`t" | |
| } | |
| Write-Host -NoNewline "$word " | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment