|
1 | | - |
2 | 1 | function Get-AbrFgtSystem { |
3 | 2 | <# |
4 | 3 | .SYNOPSIS |
@@ -250,43 +249,219 @@ function Get-AbrFgtSystem { |
250 | 249 |
|
251 | 250 | if ($interfaces -and $InfoLevel.System -ge 1) { |
252 | 251 | Section -Style Heading3 'Interfaces' { |
253 | | - $OutObj = @() |
| 252 | + Paragraph "The following section details FortiGate interfaces, grouped by interface type." |
254 | 253 |
|
255 | | - foreach ($interface in $interfaces) { |
| 254 | + # Group interfaces by their 'type' |
| 255 | + $groupedInterfaces = $interfaces | Group-Object -Property type |
256 | 256 |
|
257 | | - if ($interface.role -eq "undefined") { |
258 | | - $interface.role = "n/a" |
259 | | - } |
260 | | - $alias_description = $interface.alias |
261 | | - if ($interface.description) { |
262 | | - $alias_description += "($($interface.description))" |
263 | | - } |
264 | | - $OutObj += [pscustomobject]@{ |
265 | | - "Name" = $interface.name |
266 | | - "Alias (Description)" = $alias_description |
267 | | - "Role" = $interface.role |
268 | | - "Type" = $interface.type |
269 | | - "Vlan ID" = $interface.vlanid |
270 | | - "Mode" = $interface.mode |
271 | | - "IP Address" = $interface.ip.Replace(' ', '/') |
272 | | - #"Allow Access" = $interface.allowaccess |
273 | | - #'DHCP Relais' = $interface.'dhcp-relay-ip' |
274 | | - "Status" = $interface.status |
275 | | - #"Speed" = $interface.speed |
276 | | - } |
277 | | - } |
| 257 | + foreach ($group in $groupedInterfaces) { |
| 258 | + $interfaceType = $group.Name |
278 | 259 |
|
279 | | - $TableParams = @{ |
280 | | - Name = "Interface" |
281 | | - List = $false |
282 | | - ColumnWidths = 12, 20, 7, 11, 6, 8, 28, 8 |
283 | | - } |
| 260 | + # Create a heading for each interface type |
| 261 | + Section -Style Heading4 "$([char]::ToUpper($interfaceType[0]) + $interfaceType.Substring(1)) Interfaces" { |
| 262 | + $OutObj = @() |
284 | 263 |
|
285 | | - if ($Report.ShowTableCaptions) { |
286 | | - $TableParams['Caption'] = "- $($TableParams.Name)" |
287 | | - } |
| 264 | + foreach ($interface in $group.Group) { |
| 265 | + |
| 266 | + # Standardise interface properties |
| 267 | + $interface.name = $interface.name + $($interface.alias ? "`n($($interface.alias))" : "") |
| 268 | + $interface.role = $interface.role -eq 'undefined' ? "" : ($interface.role).ToUpper() |
| 269 | + $interface.member = $interface.member.count -gt 0 ? $interface.member.'interface-name' -join ', ' : "" |
| 270 | + $interface.mtu = $interface.'mtu-override' -eq 'disable' ? '' : $interface.mtu |
| 271 | + $interface.mode = $interface.mode -eq 'static' ? '' : $interface.mode |
| 272 | + $interface.ip = $interface.ip -eq '0.0.0.0 0.0.0.0' ? '' : $interface.ip |
| 273 | + $interface.'secondaryip' = if ($interface.'secondary-ip' -eq 'enable' -and $null -ne $interface.'secondaryip') { |
| 274 | + ($interface.'secondaryip' | ForEach-Object { |
| 275 | + $_.ip |
| 276 | + }) -join ', ' |
| 277 | + } else { |
| 278 | + "" |
| 279 | + } |
| 280 | + $interface.mode = $interface.mode -eq 'static' ? '' : $interface.mode |
| 281 | + $interface.vdom = $interface.vdom -eq 'root' ? '' : $interface.vdom |
| 282 | + $interface.vlanid = ($interface.vlanid -gt 0 ) ? $interface.vlanid : "" |
| 283 | + $interface.speed = $interface.speed -eq 'auto' ? '' : $interface.speed |
| 284 | + $interface.'remote-ip' = $interface.'remote-ip' -eq '0.0.0.0 0.0.0.0' ? '' : $interface.'remote-ip' |
| 285 | + |
| 286 | + |
| 287 | + switch ($interfaceType) { |
| 288 | + "Aggregate" { |
| 289 | + $OutObj += [pscustomobject]@{ |
| 290 | + "Name" = $interface.name |
| 291 | + "VDOM" = $interface.vdom |
| 292 | + "Role" = $interface.role |
| 293 | + "Members" = $interface.member |
| 294 | + "LACP Mode" = $interface.'lacp-mode' |
| 295 | + #"MTU" = $interface.mtu # Will be enabled next release when the TableWrite function is added |
| 296 | + "Addressing mode" = $interface.mode |
| 297 | + "IP Address" = $interface.ip |
| 298 | + #"Secondary IP" = $interface.'secondaryip' # Will be enabled next release when the TableWrite function is added |
| 299 | + "Allow Access" = $interface.allowaccess |
| 300 | + "Status" = $interface.status |
| 301 | + #"Comments" = $interface.description # Will be enabled next release when the TableWrite function is added |
| 302 | + } |
| 303 | + } |
| 304 | + "Hard-Switch" { |
| 305 | + $OutObj += [pscustomobject]@{ |
| 306 | + "Name" = $interface.name |
| 307 | + "VDOM" = $interface.vdom |
| 308 | + "Role" = $interface.role |
| 309 | + "Members" = $interface.member |
| 310 | + "MTU" = $interface.mtu |
| 311 | + "Addressing mode" = $interface.mode |
| 312 | + "IP Address" = $interface.ip |
| 313 | + #"Secondary IP" = $interface.'secondaryip' # Will be enabled next release when the TableWrite function is added |
| 314 | + "Allow Access" = $interface.allowaccess |
| 315 | + "Status" = $interface.status |
| 316 | + #"Comments" = $interface.description # Will be enabled next release when the TableWrite function is added |
| 317 | + } |
| 318 | + } |
| 319 | + "Loopback" { |
| 320 | + $OutObj += [pscustomobject]@{ |
| 321 | + "Name" = $interface.name |
| 322 | + "VDOM" = $interface.vdom |
| 323 | + "Role" = $interface.role |
| 324 | + "MTU" = $interface.mtu |
| 325 | + "IP Address" = $interface.ip |
| 326 | + "Secondary IP" = $interface.'secondaryip' |
| 327 | + "Allow Access" = $interface.allowaccess |
| 328 | + "Status" = $interface.status |
| 329 | + "Comments" = $interface.description |
| 330 | + } |
| 331 | + |
| 332 | + } |
| 333 | + "Physical"{ |
| 334 | + $OutObj += [pscustomobject]@{ |
| 335 | + "Name" = $interface.name |
| 336 | + "VDOM" = $interface.vdom |
| 337 | + "Role" = $interface.role |
| 338 | + "MTU" = $interface.mtu |
| 339 | + "Speed" = $interface.speed |
| 340 | + "Addressing mode" = $interface.mode |
| 341 | + "IP Address" = $interface.ip |
| 342 | + #"Secondary IP" = $interface.'secondaryip' # Will be enabled next release when the TableWrite function is added |
| 343 | + "Allow Access" = $interface.allowaccess |
| 344 | + "Status" = $interface.status |
| 345 | + #"Comments" = $interface.description # Will be enabled next release when the TableWrite function is added |
| 346 | + } |
| 347 | + |
| 348 | + } |
| 349 | + "Tunnel" { |
| 350 | + $OutObj += [pscustomobject]@{ |
| 351 | + "Name" = $interface.name |
| 352 | + "Parent Interface" = $interface.interface |
| 353 | + "VDOM" = $interface.vdom |
| 354 | + "Role" = $interface.role |
| 355 | + "MTU" = $interface.mtu |
| 356 | + "IP Address" = $interface.ip |
| 357 | + #"Secondary IP" = $interface.'secondaryip' # Will be enabled next release when the TableWrite function is added |
| 358 | + "Remote IP" = $interface.'remote-ip' |
| 359 | + "Allow Access" = $interface.allowaccess |
| 360 | + "Status" = $interface.status |
| 361 | + #"Comments" = $interface.description # Will be enabled next release when the TableWrite function is added |
| 362 | + } |
| 363 | + } |
| 364 | + "Vlan" { |
| 365 | + $OutObj += [pscustomobject]@{ |
| 366 | + "Name" = $interface.name |
| 367 | + "Parent Interface" = $interface.interface |
| 368 | + "VLAN ID" = $interface.vlanid |
| 369 | + "VDOM" = $interface.vdom |
| 370 | + "Role" = $interface.role |
| 371 | + #"MTU" = $interface.mtu # Will be enabled next release when the TableWrite function is added |
| 372 | + "Mode" = $interface.mode |
| 373 | + "IP Address" = $interface.ip |
| 374 | + #"Secondary IP" = $interface.'secondaryip' # Will be enabled next release when the TableWrite function is added |
| 375 | + "Allow Access" = $interface.allowaccess |
| 376 | + "Status" = $interface.status |
| 377 | + } |
| 378 | + } |
| 379 | + # vap-switch falls under default |
| 380 | + Default { |
| 381 | + $OutObj += [pscustomobject]@{ |
| 382 | + "Name" = $interface.name |
| 383 | + "VDOM" = $interface.vdom |
| 384 | + "Role" = $interface.role |
| 385 | + "MTU" = $interface.mtu |
| 386 | + "VLAN ID" = $interface.vlanid |
| 387 | + "Mode" = $interface.mode |
| 388 | + "IP Address" = $interface.ip |
| 389 | + #"Secondary IP" = $interface.'secondaryip' # Will be enabled next release when the TableWrite function is added |
| 390 | + "Allow Access" = $interface.allowaccess |
| 391 | + "Status" = $interface.status |
| 392 | + } |
| 393 | + } |
| 394 | + } |
| 395 | + } |
288 | 396 |
|
289 | | - $OutObj | Table @TableParams |
| 397 | + # VLAN interfaces |
| 398 | + if ($interfaceType -eq "vlan" -and $Options.ExcludeDownInterfaces ) { |
| 399 | + $vlanUpCount = ($OutObj | Where-Object { $_.Status -eq 'up' }).Count |
| 400 | + $vlanDownCount = ($OutObj | Where-Object { $_.Status -ne 'up' }).Count |
| 401 | + $vlanUpIDs = ($OutObj | Where-Object { $_.Status -eq 'up' } | Select-Object -ExpandProperty 'VLAN ID' | Sort-Object) |
| 402 | + $vlanDownIDs = ($OutObj | Where-Object { $_.Status -ne 'up' } | Select-Object -ExpandProperty 'VLAN ID' | Sort-Object) |
| 403 | + |
| 404 | + $VlanSummaryObj = [PSCustomObject]@{ |
| 405 | + 'Up VLANs' = "$vlanUpCount ($($vlanUpIDs -join ', '))" |
| 406 | + 'Down VLANs' = "$vlanDownCount ($($vlanDownIDs -join ', '))" |
| 407 | + 'Total VLANs' = ($vlanUpCount + $vlanDownCount) |
| 408 | + } |
| 409 | + |
| 410 | + $TableParams = @{ |
| 411 | + Name = "VLAN Summary" |
| 412 | + List = $true |
| 413 | + ColumnWidths = 20, 80 |
| 414 | + } |
| 415 | + |
| 416 | + if ($Report.ShowTableCaptions) { |
| 417 | + $TableParams['Caption'] = "- $($TableParams.Name)" |
| 418 | + } |
| 419 | + |
| 420 | + $VlanSummaryObj | Table @TableParams |
| 421 | + BlankLine |
| 422 | + } |
| 423 | + |
| 424 | + $downInterfaces = @() |
| 425 | + $upInterfaces = @() |
| 426 | + |
| 427 | + foreach ($interface in $OutObj) { |
| 428 | + if ($interface.PSObject.Properties.Name -contains 'Status') { |
| 429 | + if ($interface.Status -eq 'up') { |
| 430 | + $upInterfaces += $interface |
| 431 | + } else { |
| 432 | + $downInterfaces += $interface |
| 433 | + } |
| 434 | + } else { |
| 435 | + $downInterfaces += $interface |
| 436 | + } |
| 437 | + } |
| 438 | + |
| 439 | + if ($upInterfaces.Count -gt 0) { |
| 440 | + $TableParams = @{ |
| 441 | + Name = "$([char]::ToUpper($interfaceType[0]) + $interfaceType.Substring(1)) Interfaces" |
| 442 | + List = $false |
| 443 | + ColumnWidths = 12, 20, 7, 11, 6, 8, 20, 8, 8 |
| 444 | + } |
| 445 | + |
| 446 | + if ($Report.ShowTableCaptions) { |
| 447 | + $TableParams['Caption'] = "- $($TableParams.Name)" |
| 448 | + } |
| 449 | + |
| 450 | + # Only show interfaces based on ExcludeDownInterfaces setting |
| 451 | + if ($Options.ExcludeDownInterfaces) { |
| 452 | + $upInterfaces | Table @TableParams |
| 453 | + } else { |
| 454 | + $OutObj | Table @TableParams |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + if ($downInterfaces.Count -gt 0 -and $Options.ExcludeDownInterfaces) { |
| 459 | + $downInterfaceNames = $downInterfaces | Select-Object -ExpandProperty Name |
| 460 | + Paragraph -Style Notation "The following interface(s) were omitted due to being down: $(( $downInterfaceNames | Sort-Object ) -join ', ')." |
| 461 | + BlankLine |
| 462 | + } |
| 463 | + } |
| 464 | + } |
290 | 465 | } |
291 | 466 | } |
292 | 467 |
|
|
0 commit comments