-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade Path #159
Comments
Nice I get look for add a cmdlet for add monitor/system/firmware |
Hi, Just find out that when FortiOS is up to date, it returns the previous version instead of the current. Function Get-FirmwareUpdate{
$firmware = (Invoke-FGTRestMethod -uri api/v2/monitor/system/firmware)
$FortiOS = $firmware.results.current | select version
$CurrentMajor = $firmware.results.current.major
$CurrentMinor = $firmware.results.current.minor
$CurrentPatch = $firmware.results.current.patch
$CurrentVersion = "$($CurrentMajor)$($CurrentMinor)$($CurrentPatch)"
$CurrentVersion = $CurrentVersion -as [int]
$FullUpdate = $firmware.results.available | select version -First 1
$FullUpdateMajor = ($firmware.results.available | select -First 1).major
$FullUpdateMinor = ($firmware.results.available | select -First 1).minor
$FullUpdatePatch = ($firmware.results.available | select -First 1).patch
$FullUpdateVersion = "$($FullUpdateMajor)$($FullUpdateMinor)$($FullUpdatePatch)"
$FullUpdateVersion = $FullUpdateVersion -as [int]
$BranchUpdate = $firmware.results.available | Where-Object { $_.major -eq $CurrentMajor -and $_.minor -eq $CurrentMinor } | select version -First 1
$BranchUpdateMajor = ($firmware.results.available | Where-Object { $_.major -eq $CurrentMajor -and $_.minor -eq $CurrentMinor } | select -First 1).major
$BranchUpdateMinor = ($firmware.results.available | Where-Object { $_.major -eq $CurrentMajor -and $_.minor -eq $CurrentMinor } | select -First 1).minor
$BranchUpdatePatch = ($firmware.results.available | Where-Object { $_.major -eq $CurrentMajor -and $_.minor -eq $CurrentMinor } | select -First 1).patch
$BranchUpdateVersion = "$($BranchUpdateMajor)$($BranchUpdateMinor)$($BranchUpdatePatch)"
$BranchUpdateVersion = $BranchUpdateVersion -as [int]
if($FullUpdate){
if($CurrentVersion -ge $FullUpdateVersion){# FortiOS is fully up to date
[pscustomobject]@{
"Installé" = $($FortiOS.version)
"Disponible" = "No update available"
}
}else{
if($CurrentVersion -lt $BranchUpdateVersion){# FortiOS update available in the same firmware branch
$upgradePath = "v$($CurrentMajor).$($CurrentMinor).$($CurrentPatch)"
Do{
$nextFirmware = Invoke-FGTRestMethod -uri api/v2/monitor/system/firmware/upgrade-paths | select -ExpandProperty results | where { $_.from.major -eq $CurrentMajor -and $_.from.minor -eq $CurrentMinor -and $_.from.patch -eq $CurrentPatch -and $_.to.major -eq $BranchUpdateMajor -and $_.to.minor -eq $BranchUpdateMinor } | select -First 1
$major = $nextFirmware.to.major
$minor = $nextFirmware.to.minor
$patch = $nextFirmware.to.patch
$upgradePath = $upgradePath + " -> v$($major).$($minor).$($patch)"
}Until($major -eq $BranchUpdateMajor -and $minor -eq $BranchUpdateMinor -and $patch -eq $BranchUpdatePatch)
[pscustomobject]@{
"Installed" = $($FortiOS.version)
"Available" = $($BranchUpdate.version)
"Upgrade Path" = $upgradePath
}
}
if(($CurrentVersion -lt $FullUpdateVersion) -and ($BranchUpdateVersion -ne $FullUpdateVersion)){# FortiOS update available in a superior firmware branch
$upgradePath = "v$($CurrentMajor).$($CurrentMinor).$($CurrentPatch)"
Do{
$nextFirmware = Invoke-FGTRestMethod -uri api/v2/monitor/system/firmware/upgrade-paths | select -ExpandProperty results | where { $_.from.major -eq $CurrentMajor -and $_.from.minor -eq $CurrentMinor -and $_.from.patch -eq $CurrentPatch } | select -First 1
$major = $nextFirmware.to.major
$minor = $nextFirmware.to.minor
$patch = $nextFirmware.to.patch
$upgradePath = $upgradePath + " -> v$($major).$($minor).$($patch)"
}Until($major -eq $FullUpdateMajor -and $minor -eq $FullUpdateMinor -and $patch -eq $FullUpdatePatch)
[pscustomobject]@{
"Installed" = $($FortiOS.version)
"Available" = $($FullUpdate.version)
"Upgrade Path" = $upgradePath
}
}
}
}else{# No firmware available (support expired)
[pscustomobject]@{
"Installed" = $($FortiOS.version)
"Available" = "No firmware available, check your Fortiguard support"
}
}
} Get-FirmwareUpdate
Installed Available Upgrade Path
-------- ---------- ------------
v6.4.7 v6.4.8 v6.4.7 -> v6.4.8
v6.4.7 v7.0.5 v6.4.7 -> v7.0.5 Get-FirmwareUpdate
Installed Available Upgrade Path
-------- ---------- ------------
v6.2.9 v6.2.10 v6.2.9 -> v6.2.10 |
Thanks to your private message, here's a shortest and optimized version! Function Get-FirmwareUpdate{
$firmware = (Invoke-FGTRestMethod -uri api/v2/monitor/system/firmware)
$FortiOS = $firmware.results.current | select version
$CurrentVersion = [version]"$($firmware.results.current.major).$($firmware.results.current.minor).$($firmware.results.current.patch)"
$FullUpdate = $firmware.results.available | select version -First 1
if($FullUpdate){
$FullUpdateVersion = [version]"$(($firmware.results.available | select -First 1).major).$(($firmware.results.available | select -First 1).minor).$(($firmware.results.available | select -First 1).patch)"
$BranchUpdate = $firmware.results.available | Where-Object { $_.major -eq $CurrentVersion.Major -and $_.minor -eq $CurrentVersion.Minor } | select version -First 1
$BranchUpdateVersion = [version]"$(($firmware.results.available | Where-Object { $_.major -eq $CurrentVersion.Major -and $_.minor -eq $CurrentVersion.Minor } | select -First 1).major).$(($firmware.results.available | Where-Object { $_.major -eq $CurrentVersion.Major -and $_.minor -eq $CurrentVersion.Minor } | select -First 1).minor).$(($firmware.results.available | Where-Object { $_.major -eq $CurrentVersion.Major -and $_.minor -eq $CurrentVersion.Minor } | select -First 1).patch)"
if($CurrentVersion -ge $FullUpdateVersion){
[pscustomobject]@{
"Installed" = $($FortiOS.version)
"Available" = "No update available"
}
}else{
if($CurrentVersion -lt $BranchUpdateVersion){
$upgradePath = "v$($CurrentVersion.Major).$($CurrentVersion.Minor).$($CurrentVersion.Build)"
$major = $CurrentVersion.Major
$minor = $CurrentVersion.Minor
$patch = $CurrentVersion.Build
Do{
$nextFirmware = Invoke-FGTRestMethod -uri api/v2/monitor/system/firmware/upgrade-paths | select -ExpandProperty results | where { $_.from.major -eq $major -and $_.from.minor -eq $minor -and $_.from.patch -eq $patch -and $_.to.major -eq $BranchUpdateVersion.Major -and $_.to.minor -eq $BranchUpdateVersion.Minor } | select -First 1
$major = $nextFirmware.to.major
$minor = $nextFirmware.to.minor
$patch = $nextFirmware.to.patch
$upgradePath = $upgradePath + " -> v$($major).$($minor).$($patch)"
}Until($major -eq $BranchUpdateVersion.Major -and $minor -eq $BranchUpdateVersion.Minor -and $patch -eq $BranchUpdateVersion.Build)
[pscustomobject]@{
"Installed" = $($FortiOS.version)
"Available" = $($BranchUpdate.version)
"Upgrade Path" = $upgradePath
}
}
if(($CurrentVersion -lt $FullUpdateVersion) -and ($BranchUpdateVersion -ne $FullUpdateVersion)){
$upgradePath = "v$($CurrentVersion.Major).$($CurrentVersion.Minor).$($CurrentVersion.Build)"
$major = $CurrentVersion.Major
$minor = $CurrentVersion.Minor
$patch = $CurrentVersion.Build
Do{
$nextFirmware = Invoke-FGTRestMethod -uri api/v2/monitor/system/firmware/upgrade-paths | select -ExpandProperty results | where { $_.from.major -eq $major -and $_.from.minor -eq $minor -and $_.from.patch -eq $patch } | select -First 1
$major = $nextFirmware.to.major
$minor = $nextFirmware.to.minor
$patch = $nextFirmware.to.patch
$upgradePath = $upgradePath + " -> v$($major).$($minor).$($patch)"
}Until($major -eq $FullUpdateVersion.Major -and $minor -eq $FullUpdateVersion.Minor -and $patch -eq $FullUpdateVersion.Build)
[pscustomobject]@{
"Installed" = $($FortiOS.version)
"Available" = $($FullUpdate.version)
"Upgrade Path" = $upgradePath
}
}
}
}else{
[pscustomobject]@{
"Installed" = $($FortiOS.version)
"Available" = "No firmware available, check your Fortiguard support"
}
}
}
:-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Here's a litte function I wrote to compute upgrade path.
The text was updated successfully, but these errors were encountered: