Tech Community Live: Microsoft Intune
Oct 01 2024, 07:30 AM - 11:30 AM (PDT)
Microsoft Tech Community

Get file version Intune win32 app

Copper Contributor

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

3 Replies
Shouldn't you specify an actual file for this? For example:

C:\Users\HarmVeenstra> [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\windows\system32\ntdll.dll")

ProductVersion FileVersion FileName
-------------- ----------- --------
10.0.22621.1485 10.0.22621.1485… C:\windows\system32\ntdll.dll
Did this work out for you?
Any update?