function Get-LatestVersion {
$url = "https://github.com/abbodi1406/vcredist/releases"
$response = Invoke-WebRequest -Uri $url -UseBasicParsing
$versions = $response.Content | Select-String -Pattern "v\d+\.\d+\.\d+" -AllMatches | ForEach-Object { $_.Matches.Value }
$latestVersion = "v0.0.0"
foreach ($version in $versions) {
if ($version -match "v(\d+)\.(\d+)\.(\d+)") {
$currentVersion = "v$($matches[1]).$($matches[2]).$($matches[3])"
if ($currentVersion -gt $latestVersion) {
$latestVersion = $currentVersion
}
}
}
return $latestVersion
}
$latestVersion = Get-LatestVersion
Invoke-WebRequest -Uri "https://github.com/abbodi1406/vcredist/releases/download/$latestVersion/VisualCppRedist_AIO_x86_x64.exe" -OutFile ".\VisualCppRedist_AIO_x86_x64.exe"
Start-Process -FilePath ".\VisualCppRedist_AIO_x86_x64.exe" -ArgumentList "/y" -Wait
Remove-Item -Path ".\VisualCppRedist_AIO_x86_x64.exe"
function Get-LatestVersion {
$url = "https://github.com/abbodi1406/vcredist/releases"
$response = Invoke-WebRequest -Uri $url
$versions = $response.Content | Select-String -Pattern "v\d+\.\d+\.\d+" -AllMatches | ForEach-Object { $_.Matches.Value }
$latestVersion = "v0.0.0"
foreach ($version in $versions) {
if ($version -match "v(\d+)\.(\d+)\.(\d+)") {
$currentVersion = "v$($matches[1]).$($matches[2]).$($matches[3])"
if ($currentVersion -gt $latestVersion) {
$latestVersion = $currentVersion
}
}
}
return $latestVersion
}
$latestVersion = Get-LatestVersion
Write-Output "Latest version of the product: $latestVersion"
Invoke-WebRequest -Uri "https://github.com/abbodi1406/vcredist/releases/download/$latestVersion/VisualCppRedist_AIO_x86_x64.exe" -OutFile ".\VisualCppRedist_AIO_x86_x64.exe"
Start-Process -FilePath ".\VisualCppRedist_AIO_x86_x64.exe" -ArgumentList "/y" -Wait
Remove-Item -Path ".\VisualCppRedist_AIO_x86_x64.exe"
pause
exit
function Get-VersionsFromGitHub {
$url = "https://github.com/abbodi1406/vcredist/releases"
$response = Invoke-WebRequest -Uri $url
$versions = $response.Content | Select-String -Pattern "v\d+\.\d+\.\d+" -AllMatches | ForEach-Object { $_.Matches.Value }
return $versions
}
function Get-MaxVersion {
param (
[string[]]$versions
)
$maxVer = "v0.00.0"
foreach ($version in $versions) {
if ($version -match "v(\d+)\.(\d+)\.(\d+)") {
$currentVer = "v$($matches[1].PadLeft(2, '0')).$($matches[2].PadLeft(2, '0')).$($matches[3].PadLeft(2, '0'))"
if ($currentVer -gt $maxVer) {
$maxVer = $currentVer
}
}
}
return $maxVer
}
$versions = Get-VersionsFromGitHub
$latestVersion = Get-MaxVersion -versions $versions
Write-Output "max $latestVersion"
pause
function Get-MaxVersion {
param (
[string[]]$versions
)
$maxVer = "v0.00.0"
foreach ($version in $versions) {
if ($version -match "v(\d+)\.(\d+)\.(\d+)") {
$currentVer = "v$($matches[1].PadLeft(2, '0')).$($matches[2].PadLeft(2, '0')).$($matches[3].PadLeft(2, '0'))"
if ($currentVer -gt $maxVer) {
$maxVer = $currentVer
}
}
}
return $maxVer
}
$versions = @("v0.78.0", "v0.77.0", "v0.76.0")
$latestVersion = Get-MaxVersion -versions $versions
Write-Output "MAX: $latestVersion"
pause
вызывать так
UserInput { Функция }