用powershell
(Get-Item .\VehicleBusInterface.exe).VersionInfo.ProductVersion
完整版:
param([string]$target)
(Get-Item $target).VersionInfo.ProductVersion
第一行用来处理输入的参数:
用法:powershell.exe -file getProductVersion.ps1 -target .\IcsNeoDaemon\VehicleBusInterface\bin\Debug\VehicleBusInterface.exe
bat中输出到变量:
powershell.exe -file getProductVersion.ps1 -target .\IcsNeoDaemon\VehicleBusInterface\bin\Debug\VehicleBusInterface.exe > %Release_Num%
允许执行其它机器生成的PowerShell脚本:
set-executionpolicy remotesigned
https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts
这个也不错:
powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1
不推荐用:
PS E:> Get-ExecutionPolicy
Restricted
PS E:> Set-ExecutionPolicy UnRestricted
powershell命令行帮助:
https://technet.microsoft.com/en-us/library/dd315276.aspx?f=255&MSPPError=-2147217396
用powershell获取MSI的版本号:
https://www.scconfigmgr.com/2014/08/22/how-to-get-msi-file-information-with-powershell/
PS1:
param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[System.IO.FileInfo]$Path,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[ValidateSet("ProductCode", "ProductVersion", "ProductName", "Manufacturer", "ProductLanguage", "FullVersion")]
[string]$Property
)
Process {
try {
# Read property from MSI database
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($Path.FullName, 0))
$Query = "SELECT Value FROM Property WHERE Property = '$($Property)'"
$View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
$Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)
# Commit database and close view
$MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null)
$View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null)
$MSIDatabase = $null
$View = $null
# Return the value
return $Value
}
catch {
Write-Warning -Message $_.Exception.Message ; break
}
}
End {
# Run garbage collection and release ComObject
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($WindowsInstaller) | Out-Null
[System.GC]::Collect()
}
Command Usage:
Powershell.exe -file Get-MSIFileInformation.ps1 -Path "D:\Source$\Apps\7-zip\7z920-x64.msi" -Property ProductCode
Jenkins中执行Powershell的脚本,竟然不会自动执行 Process 部分,这跟在CMD中运行起来完全不一样!!!坑。
https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts
https://www.scconfigmgr.com/2014/08/22/how-to-get-msi-file-information-with-powershell/
(Get-Item .\VehicleBusInterface.exe).VersionInfo.ProductVersion
完整版:
param([string]$target)
(Get-Item $target).VersionInfo.ProductVersion
第一行用来处理输入的参数:
用法:powershell.exe -file getProductVersion.ps1 -target .\IcsNeoDaemon\VehicleBusInterface\bin\Debug\VehicleBusInterface.exe
bat中输出到变量:
powershell.exe -file getProductVersion.ps1 -target .\IcsNeoDaemon\VehicleBusInterface\bin\Debug\VehicleBusInterface.exe > %Release_Num%
允许执行其它机器生成的PowerShell脚本:
set-executionpolicy remotesigned
https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts
这个也不错:
powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1
不推荐用:
PS E:> Get-ExecutionPolicy
Restricted
PS E:> Set-ExecutionPolicy UnRestricted
powershell命令行帮助:
https://technet.microsoft.com/en-us/library/dd315276.aspx?f=255&MSPPError=-2147217396
用powershell获取MSI的版本号:
https://www.scconfigmgr.com/2014/08/22/how-to-get-msi-file-information-with-powershell/
PS1:
param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[System.IO.FileInfo]$Path,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[ValidateSet("ProductCode", "ProductVersion", "ProductName", "Manufacturer", "ProductLanguage", "FullVersion")]
[string]$Property
)
Process {
try {
# Read property from MSI database
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($Path.FullName, 0))
$Query = "SELECT Value FROM Property WHERE Property = '$($Property)'"
$View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
$Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)
# Commit database and close view
$MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null)
$View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null)
$MSIDatabase = $null
$View = $null
# Return the value
return $Value
}
catch {
Write-Warning -Message $_.Exception.Message ; break
}
}
End {
# Run garbage collection and release ComObject
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($WindowsInstaller) | Out-Null
[System.GC]::Collect()
}
Command Usage:
Powershell.exe -file Get-MSIFileInformation.ps1 -Path "D:\Source$\Apps\7-zip\7z920-x64.msi" -Property ProductCode
Jenkins中执行Powershell的脚本,竟然不会自动执行 Process 部分,这跟在CMD中运行起来完全不一样!!!坑。
https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts
https://www.scconfigmgr.com/2014/08/22/how-to-get-msi-file-information-with-powershell/