Functions/Public/Get-PSPuTTYTheme.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function Get-PSPuTTYTheme {
  <#
  .Synopsis
  Returns a list of supported PuTTY themes that are distributed with this PowerShell module.

  .Outputs
  [PSPuTTYTheme]
  #>

  [CmdletBinding()]
  param (
    [Parameter(Mandatory = $false)]
    [string] $Name
  )

  $Command = $PSCmdlet.MyInvocation.MyCommand.Name
  $Module = $PSCmdlet.MyInvocation.MyCommand.Module

  $ThemeFileList = Get-ChildItem -Path ('{0}\Themes' -f $Module.ModuleBase)
  $ThemeList = @()

  foreach ($ThemeFile in $ThemeFileList) {
    Write-Verbose -Message ('{0}: Processing file: {1}' -f $Command, $ThemeFile.FullName)
    $ThemeJson = Get-Content -Path $ThemeFile.FullName -Raw | ConvertFrom-Json
    $ThemeList += [PSPuTTYTheme]::new($ThemeJson)
  }

  if ($PSBoundParameters.ContainsKey('Name')) {
    Write-Output -InputObject $ThemeList.Where({ $PSItem.Name -like $Name })
  } else {
    Write-Output -InputObject $ThemeList
  }
}