From 1e5da32706a2afdbc09923ab253f592f8b78869f Mon Sep 17 00:00:00 2001 From: "U-AMERICAS\\Trevor_Squillario" Date: Fri, 8 Sep 2023 09:45:42 -0600 Subject: [PATCH] Release 3.6.2 --- CHANGELOG.md | 8 ++ DellOpenManage/DellOpenManage.psd1 | 4 +- .../Public/OME/Get-OMEFirmwareCompliance.ps1 | 110 +++++++++++------- .../Public/OME/Get-OMETemplateNetwork.ps1 | 1 + .../Public/OME/Set-OMETemplateNetwork.ps1 | 6 +- .../Public/OME/Update-OMEFirmware.ps1 | 20 +++- Documentation/CommandReference.md | 2 + .../Functions/Get-OMEFirmwareCompliance.md | 13 ++- Documentation/Functions/New-OMEAlertPolicy.md | 2 + .../Functions/Set-OMETemplateNetwork.md | 2 +- Documentation/Functions/Update-OMEFirmware.md | 13 ++- README.md | 6 + 12 files changed, 129 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4b0c86..20657cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.6.2]() - 2023-09-08 +### Fixed +- Issue with Set-OMETemplateNetwork when not specifing the -Mode parameter +- Issue with Update-OMEFirmware when -DeviceFilter is specified but no device is found. The null return value will select all devices in baseline. ([Issue #15](https://github.com/dell/OpenManage-PowerShell-Modules/issues/15)) + +### Changed +- Get-OMEFirmwareCompliance and Update-OMEFirmware to allow multiple values for -ComponentFilter ([Issue #12](https://github.com/dell/OpenManage-PowerShell-Modules/issues/12)) + ## [3.6.1]() - 2023-07-11 ### Fixed - Issue with Get-OMEJob not listing all execution histories when using the -Detail parameter diff --git a/DellOpenManage/DellOpenManage.psd1 b/DellOpenManage/DellOpenManage.psd1 index 873ef88..be2113c 100644 --- a/DellOpenManage/DellOpenManage.psd1 +++ b/DellOpenManage/DellOpenManage.psd1 @@ -3,7 +3,7 @@ # # Generated by: Trevor Squillario # -# Generated on: 7/11/2023 +# Generated on: 9/8/2023 # @{ @@ -12,7 +12,7 @@ RootModule = 'DellOpenManage.psm1' # Version number of this module. -ModuleVersion = '3.6.1' +ModuleVersion = '3.6.2' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/DellOpenManage/Public/OME/Get-OMEFirmwareCompliance.ps1 b/DellOpenManage/Public/OME/Get-OMEFirmwareCompliance.ps1 index ffe2403..df7a014 100644 --- a/DellOpenManage/Public/OME/Get-OMEFirmwareCompliance.ps1 +++ b/DellOpenManage/Public/OME/Get-OMEFirmwareCompliance.ps1 @@ -3,6 +3,36 @@ using module ..\..\Classes\Device.psm1 using module ..\..\Classes\FirmwareBaseline.psm1 using module ..\..\Classes\ComponentCompliance.psm1 +function Get-FirmwareComplianceObject($UpdateActionSet, $Component, $ComplianceDevice) { + # Check for UpdateAction to allow for downgrade of firmware + if ($UpdateActionSet.ToUpper().Contains($Component.UpdateAction)) { + # Create object for display to user + $ReportObject = [ComponentCompliance]@{ + DeviceId = $ComplianceDevice.DeviceId + ServiceTag = $ComplianceDevice.ServiceTag + DeviceModel = $ComplianceDevice.DeviceModel + DeviceName = $ComplianceDevice.DeviceName + Id = $Component.Id + Version = $Component.Version + CurrentVersion = $Component.CurrentVersion + Path = $Component.Path + Name = $Component.Name + Criticality = $Component.Criticality + UniqueIdentifier = $Component.UniqueIdentifier + TargetIdentifier = $Component.TargetIdentifier + UpdateAction = $Component.UpdateAction + SourceName = $Component.SourceName + PrerequisiteInfo = $Component.PrerequisiteInfo + ImpactAssessment = $Component.ImpactAssessment + Uri = $Component.Uri + RebootRequired = $Component.RebootRequired + ComplianceStatus = $Component.ComplianceStatus + ComponentType = $Component.ComponentType + } + return $ReportObject + } +} + function Get-OMEFirmwareCompliance { <# Copyright (c) 2018 Dell EMC Corporation @@ -31,7 +61,7 @@ limitations under the License. .PARAMETER DeviceFilter Array of type Device returned from Get-OMEDevice function. Used to limit the devices updated within the baseline. .PARAMETER ComponentFilter - String to represent component name. Used to limit the components updated within the baseline. Supports regex via Powershell -match + Array of Strings that represent component name. Used to limit the components updated within the baseline. Supports regex via Powershell -match .PARAMETER UpdateAction Determines what type of updates will be performed. (Default="Upgrade", "Downgrade", "All") .PARAMETER Output @@ -49,6 +79,10 @@ limitations under the License. "AllLatest" | Get-OMEFirmwareBaseline | Get-OMEFirmwareCompliance -ComponentFilter "iDRAC" | Format-Table Filter report by component in baseline +.EXAMPLE + "AllLatest" | Get-OMEFirmwareBaseline | Get-OMEFirmwareCompliance -ComponentFilter -ComponentFilter "iDRAC", "BIOS" | Format-Table + + Filter report by multiple components in baseline #> [CmdletBinding()] @@ -60,7 +94,7 @@ param( [Device[]]$DeviceFilter, [Parameter(Mandatory=$false)] - [String]$ComponentFilter, + [String[]]$ComponentFilter, [Parameter(Mandatory=$false)] [ValidateSet("Upgrade", "Downgrade", "All")] @@ -88,6 +122,7 @@ Process { } else { $BaselineId = $Id } + $ComplURL = $BaseUri + "/api/UpdateService/Baselines($($BaselineId))/DeviceComplianceReports" $Response = Invoke-WebRequest -Uri $ComplURL -UseBasicParsing -Headers $Headers -ContentType $Type -Method GET $DeviceComplianceReport = @() @@ -135,50 +170,49 @@ Process { # Check if the device is in the provided Devices list. Only return results for devices in the list, if a list was provided if (($DeviceFilter.Count -gt 0 -and $DeviceFilter.Id -contains $ComplianceDevice.DeviceId) -or $DeviceFilter.Count -eq 0) { $sourcesString = $null + $DeviceComplianceReportPerDevice = @() $CompList = $ComplianceDevice.'ComponentComplianceReports' if ($CompList.Length -gt 0) { # Loop through components foreach ($Component in $CompList) { - if (($ComponentFilter -ne "" -and $Component -match $ComponentFilter) -or $ComponentFilter -eq "") { - # Check for UpdateAction to allow for downgrade of firmware - if ($UpdateActionSet.ToUpper().Contains($Component.UpdateAction)) { - # Create string to be used in payload - $sourceName = $Component.'SourceName' - if ($sourcesString.Length -eq 0) { - $sourcesString += $sourceName - } - else { - $sourcesString += ';' + $sourceName - } - # Create object for display to user - $DeviceComplianceReport += [ComponentCompliance]@{ - DeviceId = $ComplianceDevice.DeviceId - ServiceTag = $ComplianceDevice.ServiceTag - DeviceModel = $ComplianceDevice.DeviceModel - DeviceName = $ComplianceDevice.DeviceName - Id = $Component.Id - Version = $Component.Version - CurrentVersion = $Component.CurrentVersion - Path = $Component.Path - Name = $Component.Name - Criticality = $Component.Criticality - UniqueIdentifier = $Component.UniqueIdentifier - TargetIdentifier = $Component.TargetIdentifier - UpdateAction = $Component.UpdateAction - SourceName = $Component.SourceName - PrerequisiteInfo = $Component.PrerequisiteInfo - ImpactAssessment = $Component.ImpactAssessment - Uri = $Component.Uri - RebootRequired = $Component.RebootRequired - ComplianceStatus = $Component.ComplianceStatus - ComponentType = $Component.ComponentType + $DeviceComplianceComponentReportObject = $null + # No Component filter set + if ($ComponentFilter.Length -eq 0) { + $DeviceComplianceComponentReportObject = Get-FirmwareComplianceObject -UpdateActionSet $UpdateActionSet -Component $Component -ComplianceDevice $ComplianceDevice + if ($null -ne $DeviceComplianceComponentReportObject) { + $DeviceComplianceReportPerDevice += $DeviceComplianceComponentReportObject + $DeviceComplianceReport += $DeviceComplianceComponentReportObject + } + } else { + foreach ($Filter in $ComponentFilter) { + if (($Filter -ne "" -and $Component.Name -match $Filter)) { + $DeviceComplianceComponentReportObject = Get-FirmwareComplianceObject -UpdateActionSet $UpdateActionSet -Component $Component -ComplianceDevice $ComplianceDevice + if ($null -ne $DeviceComplianceComponentReportObject) { + $DeviceComplianceReportPerDevice += $DeviceComplianceComponentReportObject + $DeviceComplianceReport += $DeviceComplianceComponentReportObject + } } } } } } + + # Now what we have the filtered list of updatable components, let's build the sourceString + foreach ($DeviceComplianceComponentReport in $DeviceComplianceReportPerDevice) { + # Create string to be used in payload + if ($null -ne $DeviceComplianceComponentReport) { + $sourceName = $DeviceComplianceComponentReport.'SourceName' + if ($sourcesString.Length -eq 0) { + $sourcesString += $sourceName + } + else { + $sourcesString += ';' + $sourceName + } + } + } + # Create object to be used in payload - if ( $null -ne $sourcesString) { + if ($null -ne $sourcesString) { $DeviceComplianceReportTargetList += @{ Data = $sourcesString Id = $ComplianceDevice.'DeviceId' @@ -202,9 +236,7 @@ Process { } } Catch { - Write-Error ($_.ErrorDetails) - Write-Error ($_.Exception | Format-List -Force | Out-String) - Write-Error ($_.InvocationInfo | Format-List -Force | Out-String) + Resolve-Error $_ } } diff --git a/DellOpenManage/Public/OME/Get-OMETemplateNetwork.ps1 b/DellOpenManage/Public/OME/Get-OMETemplateNetwork.ps1 index 96d29a4..003e3f0 100755 --- a/DellOpenManage/Public/OME/Get-OMETemplateNetwork.ps1 +++ b/DellOpenManage/Public/OME/Get-OMETemplateNetwork.ps1 @@ -51,6 +51,7 @@ function Get-OMETemplateNetwork { $Headers."X-Auth-Token" = $SessionAuth.Token $TemplateVlanUrl = $BaseUri + "/api/TemplateService/Templates($($Template.Id))/Views(4)/AttributeViewDetails" + Write-Verbose $TemplateVlanUrl $TemplateVlanResponse = Invoke-WebRequest -UseBasicParsing -Uri $TemplateVlanUrl -Headers $Headers -Method Get -ContentType $ContentType if ($TemplateVlanResponse.StatusCode -eq 200) { $TemplateVlanInfo = $TemplateVlanResponse.Content | ConvertFrom-Json diff --git a/DellOpenManage/Public/OME/Set-OMETemplateNetwork.ps1 b/DellOpenManage/Public/OME/Set-OMETemplateNetwork.ps1 index 34dba8f..15494a0 100644 --- a/DellOpenManage/Public/OME/Set-OMETemplateNetwork.ps1 +++ b/DellOpenManage/Public/OME/Set-OMETemplateNetwork.ps1 @@ -163,7 +163,7 @@ param( [Parameter(Mandatory=$false)] [ValidateSet("Append", "Replace", "Remove")] - [String] $Mode + [String] $Mode = "Append" ) Begin {} @@ -187,9 +187,6 @@ Process { } else { $UnTaggedNetworkId = $UnTaggedNetwork.Id } - if ($TaggedNetworkIds.Length -gt 0 -or $null -ne $UnTaggedNetwork) { - if ($null -eq $Mode) { throw [System.ArgumentNullException] "Mode parameter required when specifing -TaggedNetworks or -UnTaggedNetwork" } - } # Get network port and vlan info from existing template $VlanPortMap = Get-OMETemplateNetwork -Template $Template Write-Verbose "Current template network config" @@ -198,6 +195,7 @@ Process { -TaggedNetworkIds $TaggedNetworkIds -UnTaggedNetworkId $UnTaggedNetworkId -VlanPortMap $VlanPortMap -PropagateVlan $PropagateVlan -Mode $Mode $UpdateNetworkConfigURL = $BaseUri + "/api/TemplateService/Actions/TemplateService.UpdateNetworkConfig" $UpdateNetworkConfigPayload = $UpdateNetworkConfigPayload | ConvertTo-Json -Depth 6 + Write-Verbose "New template network config" Write-Verbose $UpdateNetworkConfigPayload $UpdateNetworkConfigResp = Invoke-WebRequest -Uri $UpdateNetworkConfigURL -UseBasicParsing -Headers $Headers -ContentType $Type -Method POST -Body $UpdateNetworkConfigPayload if ($UpdateNetworkConfigResp.StatusCode -in 200, 201) { diff --git a/DellOpenManage/Public/OME/Update-OMEFirmware.ps1 b/DellOpenManage/Public/OME/Update-OMEFirmware.ps1 index 7b846ce..6a351c1 100644 --- a/DellOpenManage/Public/OME/Update-OMEFirmware.ps1 +++ b/DellOpenManage/Public/OME/Update-OMEFirmware.ps1 @@ -137,7 +137,7 @@ limitations under the License. .PARAMETER DeviceFilter Array of type Device returned from Get-OMEDevice function. Used to limit the devices updated within the baseline. .PARAMETER ComponentFilter - String to represent component name. Used to limit the components updated within the baseline. Supports regex via Powershell -match + Array of Strings that represent component name. Used to limit the components updated within the baseline. Supports regex via Powershell -match .PARAMETER ResetiDRAC This option will restart the iDRAC. Occurs immediately, regardless if StageForNextReboot is set .PARAMETER ClearJobQueue @@ -180,6 +180,10 @@ limitations under the License. Update-OMEFirmware -Baseline $("AllLatest" | Get-OMEFirmwareBaseline) -ComponentFilter "iDRAC" -UpdateSchedule "StageForNextReboot" -ClearJobQueue Update firmware on specific components in baseline on next reboot and clear job queue before update +.EXAMPLE + Update-OMEFirmware -Baseline $("AllLatest" | Get-OMEFirmwareBaseline) -ComponentFilter "BIOS", "iDRAC" -UpdateSchedule "StageForNextReboot" -ClearJobQueue + + Update firmware on multiple specific components in baseline on next reboot and clear job queue before update #> [CmdletBinding()] @@ -191,7 +195,7 @@ param( [Device[]]$DeviceFilter, [Parameter(Mandatory=$false)] - [String]$ComponentFilter, + [String[]]$ComponentFilter, [Parameter(Mandatory)] [FirmwareBaseline]$Baseline, @@ -241,10 +245,16 @@ Process { "Graceful" = 2; "GracefulForced" = 3; } - $BaselineId = $Baseline.Id $CatalogId = $Baseline.CatalogId $RepositoryId = $Baseline.RepositoryId + + # If -DeviceFilter is $null all devices in baseline will be updated. This is a fix to ensure if a user specifies -DeviceFilter + # but it contains no devices the update will not be executed. + if ($PSBoundParameters.ContainsKey('DeviceFilter') -and $null -eq $DeviceFilter) { + throw [System.Exception]::new("Exception", "-DeviceFilter is specified but contains no devices") + } + if ($UpdateSchedule -eq "Preview") { # Only show report, do not perform any updates return Get-OMEFirmwareCompliance -Baseline $Baseline -DeviceFilter $DeviceFilter -ComponentFilter $ComponentFilter -UpdateAction $UpdateAction -Output "Report" } else { # Apply updates @@ -282,9 +292,7 @@ Process { } } Catch { - Write-Error ($_.ErrorDetails) - Write-Error ($_.Exception | Format-List -Force | Out-String) - Write-Error ($_.InvocationInfo | Format-List -Force | Out-String) + Resolve-Error $_ } } diff --git a/Documentation/CommandReference.md b/Documentation/CommandReference.md index 0209e54..3d911f4 100644 --- a/Documentation/CommandReference.md +++ b/Documentation/CommandReference.md @@ -315,6 +315,8 @@ - JobDescription (string JobDescription {get;set;}) - JobDetail (JobDetail[] JobDetail {get;set;}) - JobName (string JobName {get;set;}) +- JobType (string JobType {get;set;}) +- JobTypeId (int JobTypeId {get;set;}) - LastRun (System.Nullable[datetime] LastRun {get;set;}) - LastRunStatus (string LastRunStatus {get;set;}) - LastRunStatusId (int LastRunStatusId {get;set;}) diff --git a/Documentation/Functions/Get-OMEFirmwareCompliance.md b/Documentation/Functions/Get-OMEFirmwareCompliance.md index f3fc044..3dbfc1a 100644 --- a/Documentation/Functions/Get-OMEFirmwareCompliance.md +++ b/Documentation/Functions/Get-OMEFirmwareCompliance.md @@ -14,7 +14,7 @@ Get device firmware compliance report from OpenManage Enterprise ``` Get-OMEFirmwareCompliance [[-Baseline] ] [[-DeviceFilter] ] - [[-ComponentFilter] ] [[-UpdateAction] ] [[-Output] ] [] + [[-ComponentFilter] ] [[-UpdateAction] ] [[-Output] ] [] ``` ## DESCRIPTION @@ -44,6 +44,13 @@ Filter report by device in baseline Filter report by component in baseline +### EXAMPLE 4 +``` +"AllLatest" | Get-OMEFirmwareBaseline | Get-OMEFirmwareCompliance -ComponentFilter -ComponentFilter "iDRAC", "BIOS" | Format-Table +``` + +Filter report by multiple components in baseline + ## PARAMETERS ### -Baseline @@ -78,12 +85,12 @@ Accept wildcard characters: False ``` ### -ComponentFilter -String to represent component name. +Array of Strings that represent component name. Used to limit the components updated within the baseline. Supports regex via Powershell -match ```yaml -Type: String +Type: String[] Parameter Sets: (All) Aliases: diff --git a/Documentation/Functions/New-OMEAlertPolicy.md b/Documentation/Functions/New-OMEAlertPolicy.md index 8821ee5..f9b52a5 100755 --- a/Documentation/Functions/New-OMEAlertPolicy.md +++ b/Documentation/Functions/New-OMEAlertPolicy.md @@ -26,6 +26,8 @@ New-OMEAlertPolicy [-AlertPolicy] [] New-OMEAlertPolicy -AlertPolicy $NewAlertPolicy ``` +See README for more examples + ## PARAMETERS ### -AlertPolicy diff --git a/Documentation/Functions/Set-OMETemplateNetwork.md b/Documentation/Functions/Set-OMETemplateNetwork.md index 7ce8a79..0b2f771 100755 --- a/Documentation/Functions/Set-OMETemplateNetwork.md +++ b/Documentation/Functions/Set-OMETemplateNetwork.md @@ -139,7 +139,7 @@ Aliases: Required: False Position: 7 -Default value: None +Default value: Append Accept pipeline input: False Accept wildcard characters: False ``` diff --git a/Documentation/Functions/Update-OMEFirmware.md b/Documentation/Functions/Update-OMEFirmware.md index 3e62b2a..b1936a4 100644 --- a/Documentation/Functions/Update-OMEFirmware.md +++ b/Documentation/Functions/Update-OMEFirmware.md @@ -13,7 +13,7 @@ Update firmware on devices in OpenManage Enterprise ## SYNTAX ``` -Update-OMEFirmware [[-Name] ] [[-DeviceFilter] ] [[-ComponentFilter] ] +Update-OMEFirmware [[-Name] ] [[-DeviceFilter] ] [[-ComponentFilter] ] [-Baseline] [[-UpdateSchedule] ] [[-RebootType] ] [[-UpdateScheduleCron] ] [[-UpdateAction] ] [-ResetiDRAC] [-ClearJobQueue] [-Wait] [[-WaitTime] ] [] @@ -67,6 +67,13 @@ Update-OMEFirmware -Baseline $("AllLatest" | Get-OMEFirmwareBaseline) -Component Update firmware on specific components in baseline on next reboot and clear job queue before update +### EXAMPLE 7 +``` +Update-OMEFirmware -Baseline $("AllLatest" | Get-OMEFirmwareBaseline) -ComponentFilter "BIOS", "iDRAC" -UpdateSchedule "StageForNextReboot" -ClearJobQueue +``` + +Update firmware on multiple specific components in baseline on next reboot and clear job queue before update + ## PARAMETERS ### -Name @@ -101,12 +108,12 @@ Accept wildcard characters: False ``` ### -ComponentFilter -String to represent component name. +Array of Strings that represent component name. Used to limit the components updated within the baseline. Supports regex via Powershell -match ```yaml -Type: String +Type: String[] Parameter Sets: (All) Aliases: diff --git a/README.md b/README.md index 5182245..3f9bd3d 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,12 @@ Get device firmware compliance report. BIOS only. Select-Object -Property ServiceTag,DeviceModel,DeviceName,CurrentVersion,Version,UpdateAction,ComplianceStatus,Name | Sort-Object CurrentVersion | Format-Table ``` +Get device firmware compliance report. Multiple component filter +``` +"AllLatest" | Get-OMEFirmwareBaseline | Get-OMEFirmwareCompliance -ComponentFilter "BIOS", "iDRAC" | + Select-Object -Property ServiceTag,DeviceModel,DeviceName,CurrentVersion,Version,UpdateAction,ComplianceStatus,Name | + Sort-Object CurrentVersion | Format-Table +``` Create new firmware baseline ``` $catalog = $("Auto-Update-Online" | Get-OMECatalog)