Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GetVersionInfo和powershell的参数异常_Powershell_Getfileversion - Fatal编程技术网

GetVersionInfo和powershell的参数异常

GetVersionInfo和powershell的参数异常,powershell,getfileversion,Powershell,Getfileversion,我正在尝试使用powershell获取文件的文件版本。如果我右键单击文件并查看版本,它将显示一个值。以下是我试图做到这一点的方式: $path = "MSDE2000A"; $info = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path); 以下是它正在抛出的异常信息: Exception calling "GetVersionInfo" with "1" argument(s): "MSDE2000A.exe" At li

我正在尝试使用powershell获取文件的文件版本。如果我右键单击文件并查看版本,它将显示一个值。以下是我试图做到这一点的方式:

$path = "MSDE2000A";
$info = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path);
以下是它正在抛出的异常信息:

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

我检查过的每个文件都有相同的结果。但是,如果我的路径是c:\windows\notepad.exe,则它将按预期工作。发生了什么事?

.NET和PowerShell对当前目录的概念并不总是相同的。尝试以绝对路径通过

[Diagnostics.FileVersionInfo]::GetVersionInfo('C:\Windows\System32\user32.dll')

ProductVersion   FileVersion      FileName
--------------   -----------      --------
6.1.7600.16385   6.1.7600.1638... C:\Windows\System32\user32.dll
此外,您还可以使用get ChildItem获得此信息,例如:

Get-ChildItem C:\Windows\System32\user32.dll | fl VersionInfo

.NET和PowerShell对当前目录的概念并不总是相同的。尝试以绝对路径通过

[Diagnostics.FileVersionInfo]::GetVersionInfo('C:\Windows\System32\user32.dll')

ProductVersion   FileVersion      FileName
--------------   -----------      --------
6.1.7600.16385   6.1.7600.1638... C:\Windows\System32\user32.dll
此外,您还可以使用get ChildItem获得此信息,例如:

Get-ChildItem C:\Windows\System32\user32.dll | fl VersionInfo