Search-Dictionary.psm1

<#
.Synopsis
   Displays information on a given word from the dictionary
.DESCRIPTION
  This uses dictionaryapi.dev to obtain the information displayed to you. To my knowledge no dictionary checkers are available
  as a module on the Powershell Gallery, due to my fondness of the English language and always looking for the most appropriate
  word to use, I thought creating a module to do just that would be a jolly good idea. This will return the definition of the
  word, an example of using the word, an audio clip of the phonetics of the word and finally a web link to wiktionary.org to
  find out even more information on this word you search for. Not every result contains examples and audio.
 
.PARAMETER Word
This is a single string word. So no need for speech-marks when using this parameter if you do not wish to do so. A single string
is specified as the word to search. Like if you wanted to know about the word barbaric then use -Word Barbaric as the string to
pass as the parameter.
 
.EXAMPLE
   Search-Dictionary -Word facetious
 
   You searched for the word:- facetious
 
The definition of facetious is:- Treating serious issues with (often deliberately) inappropriate humour; flippant. Pleasantly hum
orous; jocular.
 
An example of facetious would be:- Robbie's joke about Heather's appearance was just him being facetious.
 
Phonetics of this word can be listened to here:- https://commons.wikimedia.org/w/index.php?curid=11518620
 
To find out more about facetious go check out:- https://en.wiktionary.org/wiki/facetious
 
.EXAMPLE
   Search-Dictionary -Word ostentatious
 
You searched for the word:- ostentatious
 
The definition of ostentatious is:- Of ostentation. Intended to attract notice. Of tawdry display; kitsch.
 
An example of ostentatious would be:-
 
Phonetics of this word can be listened to here:-
 
To find out more about ostentatious go check out:- https://en.wiktionary.org/wiki/ostentatious
 
#>

function Search-Dictionary {
    Param
    (
        [Parameter(Mandatory = $true,
            Position = 0)]
        [string]$Word
    )

    Begin {
        Write-Verbose -Message "Starting script at $(Get-Date)"
    }
    Process {
        foreach ($item in $Word) {
            Write-Verbose -Message "You would like to find the word $item within the dictionary"
            try {
                $dictionary = Invoke-RestMethod -Uri "https://api.dictionaryapi.dev/api/v2/entries/en/$Word" -ErrorAction Stop
                Write-Host -ForegroundColor Green "You searched for the word:- $($dictionary.word)"
                Write-Host
                Write-Host -ForegroundColor Green "The definition of $($dictionary.word) is:- $($dictionary.meanings.definitions.definition)"
                Write-Host
                Write-Host -ForegroundColor Green "An example of $($dictionary.word) would be:- $($dictionary.meanings.definitions.example)"
                Write-Host
                Write-Host -ForegroundColor Green "Phonetics of this word can be listened to here:- $($dictionary.phonetics.sourceUrl)"
                Write-Host
                Write-Host -ForegroundColor Green "To find out more about $($dictionary.word) go check out:- $($dictionary.sourceurls)"
            } #End Try block
            catch {
                Write-Warning "Something went wrong the word you searched for could not be found"
                $_ | ConvertFrom-Json | Format-List
            } #End Catch block
        } #End Foreach block
    } #End Process block
    End {
    }
} #End Function