Mar 30 2023 03:27 PM
Trying to get the file version of a specific application. I took the path to the binary file in the registry and add it to this script below. But it errors out
Original Script
$FileVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("<path to binary file>").FileVersion
#The below line trims the spaces before and after the version name
$FileVersion = $FileVersion.Trim();
if ("<file version of successfully detected file>" -eq $FileVersion)
{
#Write the version to STDOUT by default
$FileVersion
exit 0
}
else
{
#Exit with non-zero failure code
exit 1
}
I added the file to the path - Is this correct?
$FileVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{BFDF03B4-DDBB-4A1D-9CD4-3DD80BE3DA4F}").FileVersion
#The below line trims the spaces before and after the version name
$FileVersion = $FileVersion.Trim();
if ("<file version of successfully detected file>" -eq $FileVersion)
{
#Write the version to STDOUT by default
$FileVersion
exit 0
}
else
{
#Exit with non-zero failure code
exit 1
}
Error
PS C:\Windows\system32> \\abc.local\share\DKM\UserData\John_Doe\Documents\PS Scripts\Win32appfileversion.ps1
Exception calling "GetVersionInfo" with "1" argument(s): "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{BFDF03B4-DDBB-4A1D-9CD4-3DD80BE3DA4F}"
At \\abc.local\share\DKM\UserData\John_Doe\Documents\PS Scripts\Win32appfileversion.ps1:1 char:1
+ $FileVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo(" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
You cannot call a method on a null-valued expression.
At \\abc.local\share\DKM\UserData\John_Doe\Documents\PS Scripts\Win32appfileversion.ps1:3 char:1
+ $FileVersion = $FileVersion.Trim();
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Apr 01 2023 11:11 AM