当我从powershell运行下面的powershell命令来获取应用程序版本时,我得到了正确的响应
(Get-Item "C:\\Program Files\\CompanyName\\AppName\\bin\\AppLauncher.exe").VersionInfo.FileVersion
但是,我需要从批处理文件中运行它,所以我在批处理文件中添加了以下内容。
powershell -Command " & (Get-Item 'C:\\Program Files\\CompanyName\\AppName\\bin\\AppLauncher.exe').VersionInfo.FileVersion"
执行此命令时,我看到在控制台上返回了版本,但有异常
& : The term '1.2.0.33' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:4
+ & (Get-Item 'C:\\Program Files\\CompanyName\\AppName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (1.2.0.33:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
上面错误中的'1.2.0.33‘是我期望它返回的版本。
另外,如果可以建议如何将其赋值给变量。
发布于 2020-07-15 22:00:41
您应该能够使用以下两种方法之一:
@%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoProfile "(Get-Item \"%ProgramFiles%\CompanyName\AppName\bin\AppLauncher.exe\").VersionInfo.FileVersion"
或者:
@%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoProfile "(Get-Item \"$Env:ProgramFiles\CompanyName\AppName\bin\AppLauncher.exe\").VersionInfo.FileVersion"
如果你想把它保存为一个变量,那么也许:
@For /F %%G In ('%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoProfile "(Get-Item \"%ProgramFiles%\CompanyName\AppName\bin\AppLauncher.exe\").VersionInfo.FileVersion"') Do @Set VerInfo=%%G
或者:
@For /F %%G In ('%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoProfile "(Get-Item \"$Env:ProgramFiles\CompanyName\AppName\bin\AppLauncher.exe\").VersionInfo.FileVersion"') Do @Set VerInfo=%%G
https://stackoverflow.com/questions/62916091
复制相似问题