I have the following function which compares a file version string to an actual file and returns 1 if the file is lower:
function FileVersionDetectionCheck() {
param([string]$file)
$fileversion = (get-item $file).VersionInfo.ProductVersion
$fileversionobject = [System.Version]$fileversion
$targetversion = [System.Version]::Parse("11.0.9700")
Write-Output "File Version:" $fileversionobject
Write-Output "Target Version:" $targetversion
if($fileversionobject -ge $targetversion) {
return 0
}
else {
return 1
}
}
FileVersionDetectionCheck("C:\program files\internet explorer\iexplore.exe")
This code works fine. However, if I add a second string parameter...
function FileVersionDetectionCheck() {
param([string]$file,[string]$version)
$fileversion = (get-item $file).VersionInfo.ProductVersion
$fileversionobject = [System.Version]$fileversion
#$targetversion = [System.Version]::Parse("11.0.9700")
$targetversion = [System.Version]$version
Write-Output "File Version:" $fileversionobject
Write-Output "Target Version:" $targetversion
if($fileversionobject -ge $targetversion) {
return 0
}
else {
return 1
}
}
FileVersionDetectionCheck("C:\program files\internet explorer\iexplore.exe",
"11.0.9700")
It errors out with:
get-item : Cannot find path 'C:\program files\internet explorer\iexplore.exe 11.0.9700' because it does not exist.
Seems to be reading both parameters as a single string.
As far as I can tell this is a valid way to pass multiple parameters to a function. Am I doing something wrong or could this be a bug?