Windows/Powershell将程序版本转换为变量 [英] Windows / Powershell get Program Version into variable

查看:32
本文介绍了Windows/Powershell将程序版本转换为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很近,但不在那儿.我可以通过powershell来获取我的应用程序的版本,但是它附带了很多文字.

I'm close but not there. I can get the version of my application via powershell, but it's got a bunch of text along with it.

此命令:

powershell -NoLogo -NoProfile -Command ^
    (get-item -Path 'c:\myapp.exe').VersionInfo ^| ^
        Format-List -Force | findstr "ProductVersion" > c:\version.txt

产生(在文本文件中):产品版本:1.6.7.0

produces (in a text file): ProductVersion : 1.6.7.0

是否可以通过Powershell中的单个命令拆分它?我无法在我的环境中运行ps脚本.但是,如果可以的话,我将运行以下命令:

Is it possible via a single command in powershell to split it? I can't run ps scripts in my environment. But if I could, I would run this:

$mystr = (get-item -Path 'c:\myapp.exe').VersionInfo | Format-List -Force | findstr ProductVersion
$arr = $mystr -split ": "
$arr[1]

有没有办法将其放在一行上并放入环境(批量)变量中?

Is there a way to put this on a single line and put it into a environment (batch) variable?

推荐答案

鉴于您提供的方法进行了一些修改,也许可以做到这一点?

Given your provided method, with some modification, perhaps this would do it?

@Echo Off
For /F "Delims=" %%A In ('Powershell -C^
 "(GI 'C:\myapp.exe').VersionInfo.ProductVersion"') Do Set "PV=%%A"
Echo=%PV%
Pause

这篇关于Windows/Powershell将程序版本转换为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆