Created
February 4, 2023 18:04
-
-
Save joegasper/53833312d833640bfc89d6223b6620e7 to your computer and use it in GitHub Desktop.
Given a path, determine installed version of PHP
This file contains 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
function Get-PHPVersion { | |
<# | |
.SYNOPSIS | |
Given a path, determine installed version of PHP. | |
.DESCRIPTION | |
The provided path will be searched for php.exe files and return the version of found PHP executables. | |
.PARAMETER Path | |
Path to search | |
.EXAMPLE | |
Get-PHPVersions -Path E:\PHP | |
FileVersion FullName | |
----------- -------- | |
7.3.33 E:\PHP\7.3_latest\php.exe | |
7.3.26 E:\PHP\7.3_previous\php.exe | |
7.4.33 E:\PHP\7.4_latest\php.exe | |
7.4.27 E:\PHP\7.4_previous\php.exe | |
8.1.13 E:\PHP\8.1_latest\php.exe | |
8.1.2 E:\PHP\8.1_previous\php.exe | |
Search E:\PHP | |
.EXAMPLE | |
'.\7.3_latest','.\7.4_latest' | Get-PHPVersion | |
FileVersion FullName | |
----------- -------- | |
7.3.33 E:\PHP\7.3_latest\php.exe | |
7.4.33 E:\PHP\7.4_latest\php.exe | |
Search two folders and pass them via the pipeline. | |
#> | |
[CmdletBinding()] | |
[OutputType([String])] | |
param ( | |
[Parameter(Mandatory=$false, | |
ValueFromPipeline=$true)] | |
[string[]] | |
$Path = '.' | |
) | |
Begin {} | |
Process | |
{ | |
foreach ($P in $Path) { | |
try { | |
$rPath = Resolve-Path -Path $P -ErrorAction Stop | |
$PHPEXEs = Get-ChildItem -Path $rPath -Filter 'php.exe' -Recurse | |
} | |
catch | |
{ | |
Write-Warning "Cannot find path: $P" | |
break | |
} | |
foreach ($PHPEXE in $PHPEXEs) { | |
[PSCustomObject]@{ | |
'FileVersion' = $PHPEXE.VersionInfo.FileVersion; | |
'FullName' = $PHPEXE.FullName; | |
} | |
} | |
} | |
} | |
End {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment