Private/Get-TerraformInstalledVersionList.ps1
Function Get-TerraformInstalledVersionList { [CmdletBinding()] param ( [Parameter()] [string] $Version ) Write-Verbose "Retrieving List of Installed Terraform Versions" $tfVersions = Get-ChildItem $env:TFSWITCH_BASEDIR -Recurse -File -Filter 'terraform.exe' if ( !$tfversions ) { Write-Warning "No Terraform Install found in location $env:TFSWITCH_BASEDIR" } elseif ( $Version ) { Write-Verbose "Filtering for Version [$Version]" } $return = $tfVersions | ForEach-Object { $versionTemp = Split-Path $_ -Parent | Split-Path -Leaf New-Object psobject -Property ([ordered]@{ Version = $versionTemp isActive = $versionTemp -eq $env:TFSWITCH_VERSION Path = $_.FullName }) } if ( $Version ) { $return = $return | Where-Object { $_.Version -eq $Version } if ( !$return ) { Write-Warning "[$Version] version not found locally." } } return $return } |