I am trying to use powershell to get the file version of a file. If I right click the file and look at the version, it shows a value. Here is how I am trying to do it:
$path = "MSDE2000A";
$info = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path);
Here is the exception information it is throwing:
Exception calling "GetVersionInfo" with "1" argument(s): "MSDE2000A.exe"
At line:1 char:58
+ $f = [system.diagnostics.fileversioninfo]::getversioninfo <<<< ("MSDE2000A.exe")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Every file I've checked has the sames result. However, if my path is c:\windows\notepad.exe (as in the example) it works as expected. What's going on?
.NET and PowerShell's notion of current directory aren't always the same. Try passing in the absolute path.
Also, you can get this information with Get-ChildItem like so: