Powershell 如何从网站获取版本字符串并进行比较?

Powershell 如何从网站获取版本字符串并进行比较?,powershell,Powershell,我已经创建了一个用于更新程序的PowerShell脚本,但我只想在上的版本号大于Test.txt文件中的版本号时下载它 如何比较这些字符串 $FileName = "$PSScriptRoot\SysinternalsSuite.zip" Get-Content $PSScriptRoot\Test.txt (New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/s/12uecxcxq2rt0s4/um.zip?dl=

我已经创建了一个用于更新程序的PowerShell脚本,但我只想在上的版本号大于Test.txt文件中的版本号时下载它

如何比较这些字符串

$FileName = "$PSScriptRoot\SysinternalsSuite.zip"

Get-Content $PSScriptRoot\Test.txt

(New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/s/12uecxcxq2rt0s4/um.zip?dl=1',"$FileName ");
(new-object -com shell.application).namespace("$PSScriptRoot").CopyHere((new-object -com shell.application).namespace("$FileName").Items(),16)
if (Test-Path $FileName) {
  Remove-Item $FileName
}

我建议使用
[version]
类型加速器进行比较。例如:

$LocalVersion = [version](Get-Content $PSScriptRoot\test.txt)
$RemoteVersion = [version](Invoke-RestMethod http://come-join.us/update/test.txt)

If ($LocalVersion -lt $RemoteVersion) {
    $true
}
版本加速器将版本字符串转换为System.Version.NET类对象:

~\Documents> $RemoteVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      1      -1      
然后可以使用所有标准比较运算符进行比较