Comments (3)
Nice
I get look for add a cmdlet for add monitor/system/firmware
from powerfgt.
Hi,
Just find out that when FortiOS is up to date, it returns the previous version instead of the current.
This is a fix for this behaviour.
Also add the upgrade path if you want to stay in the same firmware branch.
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
from powerfgt.
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"
}
}
}
:-)
from powerfgt.
Related Issues (20)
- Upgrade path error HOT 2
- Backup config isn't working HOT 1
- When using the "Remove-FGTFirewallAddressGroupMember" cmdlet, nothing happens HOT 12
- Reg Connect-FGT HOT 4
- Connecting with FortiToken? HOT 3
- Getting Arp Table HOT 2
- Can you create new users? HOT 9
- Upload and replace renewed SSL Certificate offline HOT 3
- Move-FGTFirewallPolicy function problem HOT 1
- Custom HTTPS port? HOT 1
- Error when using "-since" option with Get-FGTLogTraffic command HOT 2
- Unexpected behavior with log search - Get-FGTLogTraffic HOT 6
- MAC address feature request! HOT 1
- add ability to add security profile to firewall policy HOT 4
- Unable to concatenate -srcip and -dstip in the Get-FGTLogTraffic function. HOT 6
- Feature request: DHCP Server support HOT 2
- Invoke-FGTRestMethod - Bad Gateway When Trying To Create Custom Service HOT 5
- Content-Type required but not specified for Invoke-RestMethod HOT 8
- Signing module Powershell PowerFGT HOT 1
- PS 7.4.2, restmethod.ps1 ContentType application/json HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powerfgt.