diff --git a/.github/workflows/publish-module.yml b/.github/workflows/publish-module.yml index 1c6b02b..6e827fb 100644 --- a/.github/workflows/publish-module.yml +++ b/.github/workflows/publish-module.yml @@ -2,9 +2,8 @@ name: Publish Module to PowerShell Gallery # Only trigger on published releases on: - push: - release: - types: [published] + release: + types: [published] jobs: publish-to-gallery: diff --git a/CHANGELOG.md b/CHANGELOG.md index b55017a..49732f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ 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). -## [2.3.0]() +## [2.3.1]() - 2021-09-14 ### Added - Migrated scripts from https://github.com/dell/OpenManage-Enterprise/tree/master/PowerShell - Get-OMEAuditLog @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Changed Invoke-OMETemplateDeploy to use SecureString for -NetworkBootSharePassword +- Added -UseAllProtocols parameter to New-OMEDiscovery ([Issue #4](https://github.com/dell/OpenManage-PowerShell-Modules/issues/4)) ### Fixed - Fixed Set-CertPolicy to allow multiple Connect-OME within script ([Issue #2](https://github.com/dell/OpenManage-PowerShell-Modules/issues/2)) diff --git a/DellOpenManage/Classes/SessionAuth.psm1 b/DellOpenManage/Classes/SessionAuth.psm1 index 208ee9e..c45fe18 100644 --- a/DellOpenManage/Classes/SessionAuth.psm1 +++ b/DellOpenManage/Classes/SessionAuth.psm1 @@ -2,5 +2,6 @@ Class SessionAuth { [String]$Id [String]$Host [String]$Token + [System.Version]$Version [Boolean]$IgnoreCertificateWarning } \ No newline at end of file diff --git a/DellOpenManage/DellOpenManage.psd1 b/DellOpenManage/DellOpenManage.psd1 index 8e14d33..c30e07c 100644 --- a/DellOpenManage/DellOpenManage.psd1 +++ b/DellOpenManage/DellOpenManage.psd1 @@ -3,7 +3,7 @@ # # Generated by: Trevor Squillario # -# Generated on: 9/3/2021 +# Generated on: 9/14/2021 # @{ @@ -12,7 +12,7 @@ RootModule = 'DellOpenManage.psm1' # Version number of this module. -ModuleVersion = '2.3.0' +ModuleVersion = '2.3.1' # Supported PSEditions # CompatiblePSEditions = @() @@ -27,7 +27,7 @@ Author = 'Trevor Squillario ' CompanyName = 'Dell EMC' # Copyright statement for this module -Copyright = '(c) 2020 Dell EMC. All rights reserved.' +Copyright = '(c) 2021 Dell EMC. All rights reserved.' # Description of the functionality provided by this module Description = 'Dell OpenManage Enterprise PowerShell Module' diff --git a/DellOpenManage/Public/OME/Connect-OMEServer.ps1 b/DellOpenManage/Public/OME/Connect-OMEServer.ps1 index 76dd452..3647773 100644 --- a/DellOpenManage/Public/OME/Connect-OMEServer.ps1 +++ b/DellOpenManage/Public/OME/Connect-OMEServer.ps1 @@ -83,12 +83,29 @@ param( $SessResponse = Invoke-WebRequest -Uri $SessionUrl -Method Post -Body $UserDetails -ContentType $Type if ($SessResponse.StatusCode -eq 200 -or $SessResponse.StatusCode -eq 201) { $SessResponseData = $SessResponse.Content | ConvertFrom-Json + + $Token = [String]$SessResponse.Headers["X-Auth-Token"] + $Headers = @{} + $Headers."X-Auth-Token" = $Token + + # Get Appliance Version + $AppInfoUrl = "https://$($OMEHost)/api/ApplicationService/Info" + $AppInfoResponse = Invoke-WebRequest -Uri $AppInfoUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type + $AppVersion = [System.Version]"1.0.0" + if ($AppInfoResponse.StatusCode -eq 200 -or $AppInfoResponse.StatusCode -eq 201) { + $AppInfoResponseData = $AppInfoResponse.Content | ConvertFrom-Json + Write-Verbose $($AppInfoResponseData) + $AppVersion = [System.Version]$AppInfoResponseData.Version + } + $Script:SessionAuth = [SessionAuth]@{ Host = $OMEHost - Token = $SessResponse.Headers["X-Auth-Token"] + Token = $Token Id = $SessResponseData.Id + Version = $AppVersion IgnoreCertificateWarning = $IgnoreCertificateWarning } + } else { Write-Error "Unable to create a session with appliance $($OMEHost)" } diff --git a/DellOpenManage/Public/OME/Edit-OMESupportAssistGroup.ps1 b/DellOpenManage/Public/OME/Edit-OMESupportAssistGroup.ps1 index 691d859..3492e11 100644 --- a/DellOpenManage/Public/OME/Edit-OMESupportAssistGroup.ps1 +++ b/DellOpenManage/Public/OME/Edit-OMESupportAssistGroup.ps1 @@ -85,6 +85,12 @@ Begin { Break Return } + # Add version check for SupportAssist commandlets + if ($SessionAuth.Version -lt [System.Version]"3.5.0") { + Write-Error "SupportAssist API not supported in version $($SessionAuth.Version) of OpenManage Enterprise" + Break + Return + } } Process { Try { diff --git a/DellOpenManage/Public/OME/Get-OMESupportAssistCase.ps1 b/DellOpenManage/Public/OME/Get-OMESupportAssistCase.ps1 index f5b3ffd..690bfa3 100644 --- a/DellOpenManage/Public/OME/Get-OMESupportAssistCase.ps1 +++ b/DellOpenManage/Public/OME/Get-OMESupportAssistCase.ps1 @@ -47,6 +47,12 @@ Begin { Break Return } + # Add version check for SupportAssist commandlets + if ($SessionAuth.Version -lt [System.Version]"3.5.0") { + Write-Error "SupportAssist API not supported in version $($SessionAuth.Version) of OpenManage Enterprise" + Break + Return + } } Process { diff --git a/DellOpenManage/Public/OME/Get-OMESupportAssistGroup.ps1 b/DellOpenManage/Public/OME/Get-OMESupportAssistGroup.ps1 index 17de6d0..10c3c52 100644 --- a/DellOpenManage/Public/OME/Get-OMESupportAssistGroup.ps1 +++ b/DellOpenManage/Public/OME/Get-OMESupportAssistGroup.ps1 @@ -48,6 +48,12 @@ Begin { Break Return } + # Add version check for SupportAssist commandlets + if ($SessionAuth.Version -lt [System.Version]"3.5.0") { + Write-Error "SupportAssist API not supported in version $($SessionAuth.Version) of OpenManage Enterprise" + Break + Return + } } Process { diff --git a/DellOpenManage/Public/OME/New-OMEDiscovery.ps1 b/DellOpenManage/Public/OME/New-OMEDiscovery.ps1 index 01b43ce..a70cae6 100644 --- a/DellOpenManage/Public/OME/New-OMEDiscovery.ps1 +++ b/DellOpenManage/Public/OME/New-OMEDiscovery.ps1 @@ -1,5 +1,5 @@  -function Get-DiscoverDevicePayload($Name, $HostList, $DeviceType, $DiscoveryUserName, [SecureString] $DiscoveryPassword, $Email, $SetTrapDestination, $Schedule, $ScheduleCron) { +function Get-DiscoverDevicePayload($Name, $HostList, $DeviceType, $DiscoveryUserName, [SecureString] $DiscoveryPassword, $Email, $SetTrapDestination, $UseAllProtocols, $Schedule, $ScheduleCron) { $DiscoveryConfigPayload = '{ "DiscoveryConfigGroupName":"Server Discovery", "DiscoveryStatusEmailRecipient":"", @@ -70,6 +70,10 @@ function Get-DiscoverDevicePayload($Name, $HostList, $DeviceType, $DiscoveryUser $DiscoveryConfigPayload.DiscoveryStatusEmailRecipient.PSObject.Properties.Remove("DiscoveryConfigTargets") } $DiscoveryConfigPayload.TrapDestination = $SetTrapDestination + # Add version check for UseAllProfiles + if ($SessionAuth.Version -ge [System.Version]"3.7.0") { + $DiscoveryConfigPayload | Add-Member -NotePropertyName UseAllProfiles -NotePropertyValue $UseAllProtocols + } $DiscoveryConfigPayload.DiscoveryConfigModels[0].PSObject.Properties.Remove("DiscoveryConfigTargets") $DiscoveryConfigPayload.DiscoveryConfigModels[0]| Add-Member -MemberType NoteProperty -Name 'DiscoveryConfigTargets' -Value @() foreach ($DiscoveryHost in $HostList) { @@ -166,6 +170,8 @@ limitations under the License. Email upon completion .PARAMETER SetTrapDestination Set trap destination of iDRAC to OpenManage Enterprise upon discovery +.PARAMETER UseAllProtocols + Execute all selected protocols when discovering devices. This will increase this discovery task's execution time. .PARAMETER Schedule Determines when the discovery job will be executed. (Default="RunNow", "RunLater") .PARAMETER ScheduleCron @@ -232,6 +238,9 @@ param( [String[]] $Protocol = @("wsman", "redfish"), #> + [Parameter(Mandatory=$false)] + [Switch]$UseAllProtocols, + [Parameter(Mandatory=$false)] [Switch]$Wait, @@ -256,9 +265,9 @@ Process { $DiscoverUrl = $BaseUri + "/api/DiscoveryConfigService/DiscoveryConfigGroups" if ($Hosts.Count -gt 0) { - $Payload = Get-DiscoverDevicePayload -Name $Name -HostList $Hosts -DeviceType $DeviceType -DiscoveryUserName $DiscoveryUserName -DiscoveryPassword $DiscoveryPassword -Email $Email -SetTrapDestination $SetTrapDestination.IsPresent -Schedule $Schedule -ScheduleCron $ScheduleCron + $Payload = Get-DiscoverDevicePayload -Name $Name -HostList $Hosts -DeviceType $DeviceType -DiscoveryUserName $DiscoveryUserName -DiscoveryPassword $DiscoveryPassword -Email $Email -SetTrapDestination $SetTrapDestination -UseAllProtocols $UseAllProtocols -Schedule $Schedule -ScheduleCron $ScheduleCron $Payload = $Payload | ConvertTo-Json -Depth 6 - $DiscoverResponse = Invoke-WebRequest -Uri $DiscoverUrl -UseBasicParsing -Method Post -Body $Payload -Headers $Headers -ContentType $Type + $DiscoverResponse = Invoke-WebRequest -Uri $DiscoverUrl -UseBasicParsing -Method Post -Body $Payload -Headers $Headers -ContentType $Type if ($DiscoverResponse.StatusCode -eq 201) { Write-Verbose "Discovering devices...." Start-Sleep -Seconds 10 @@ -280,9 +289,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/New-OMESupportAssistGroup.ps1 b/DellOpenManage/Public/OME/New-OMESupportAssistGroup.ps1 index 7626a5a..8fba25f 100644 --- a/DellOpenManage/Public/OME/New-OMESupportAssistGroup.ps1 +++ b/DellOpenManage/Public/OME/New-OMESupportAssistGroup.ps1 @@ -202,11 +202,17 @@ param( ## Script that does the work Begin { - if(!$SessionAuth.Token){ - Write-Error "Please use Connect-OMEServer first" - Break - Return - } + if(!$SessionAuth.Token){ + Write-Error "Please use Connect-OMEServer first" + Break + Return + } + # Add version check for SupportAssist commandlets + if ($SessionAuth.Version -lt [System.Version]"3.5.0") { + Write-Error "SupportAssist API not supported in version $($SessionAuth.Version) of OpenManage Enterprise" + Break + Return + } } Process { diff --git a/DellOpenManage/Public/OME/Remove-OMESupportAssistGroup.ps1 b/DellOpenManage/Public/OME/Remove-OMESupportAssistGroup.ps1 index f9efd5d..8eae4d4 100644 --- a/DellOpenManage/Public/OME/Remove-OMESupportAssistGroup.ps1 +++ b/DellOpenManage/Public/OME/Remove-OMESupportAssistGroup.ps1 @@ -44,6 +44,12 @@ Begin { Break Return } + # Add version check for SupportAssist commandlets + if ($SessionAuth.Version -lt [System.Version]"3.5.0") { + Write-Error "SupportAssist API not supported in version $($SessionAuth.Version) of OpenManage Enterprise" + Break + Return + } } Process { Try { diff --git a/DellOpenManage/Public/OME/Set-OMEPowerState.ps1 b/DellOpenManage/Public/OME/Set-OMEPowerState.ps1 index 0b9f089..bbb31d9 100644 --- a/DellOpenManage/Public/OME/Set-OMEPowerState.ps1 +++ b/DellOpenManage/Public/OME/Set-OMEPowerState.ps1 @@ -147,11 +147,14 @@ Process { if($PowerState){ if($PowerControlStateMap[$State] -eq $PowerState ){ Write-Verbose "Device is already in the desired state." + return "Completed" }elseif(($State -eq "On") -and ($PowerState -eq $PowerStateMap["PoweringOn"])){ Write-Verbose "Device is already in the desired state." + return "Completed" } elseif(($State -eq "Off") -and ($PowerState -eq $PowerStateMap["PoweringOff"])){ Write-Verbose "Device is already in the desired state. " + return "Completed" } else{ $JobServicePayload = Get-JobServicePayload @@ -173,6 +176,7 @@ Process { else { Write-Error "Unable to $($State) device..." Write-Error $JobResponse + return "Failed" } } } diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000..53e79be --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,28 @@ +# Release Process + +## Run Pester Tests +``` +.\Tests\Main.Tests.ps1 -Server "192.168.1.100" +``` + +## Run PSScriptAnalyzer +``` +.\Tests\Invoke-PSScriptAnalyzer.ps1 +``` + +## Bump Version +``` +.\Build-Module.ps1 -Version 2.3.1 +``` + +## Commit Changes +``` +git checkout main +git merge devel +git commit -m 'Release 2.3.1' + +# Only tag releases as this triggers a git workflow (.github/workflows/create-release.yml) +git tag v2.3.1 +git push origin v2.3.1 +git push origin main +``` \ No newline at end of file diff --git a/Tests/Device.Tests.ps1 b/Tests/Device.Tests.ps1 index 41f4fa1..b8eb0d7 100644 --- a/Tests/Device.Tests.ps1 +++ b/Tests/Device.Tests.ps1 @@ -31,7 +31,7 @@ Describe "Device Tests" { } It "Should submit job to power on device" { - $TestDeviceServiceTags | Set-OMEPowerState -State "On" | Should -BeOfType System.Int64 + $TestDeviceServiceTags | Set-OMEPowerState -State "On" | Should -Be "Completed" } } } \ No newline at end of file diff --git a/Tests/Firmware.Tests.ps1 b/Tests/Firmware.Tests.ps1 index f3e0149..db052d3 100644 --- a/Tests/Firmware.Tests.ps1 +++ b/Tests/Firmware.Tests.ps1 @@ -49,7 +49,7 @@ Describe "Firmware Tests" { It "Should try to update firmware from DUP with preview only" -Tag "DUP" { $devices = $($DeviceServiceTag | Get-OMEDevice -FilterBy "ServiceTag") - Update-OMEFirmwareDUP -Device $devices -UpdateSchedule "Preview" -DupFile "C:\Temp\BIOS_92RFG_WN64_2.11.2.EXE" | Measure-Object | Select-Object -ExpandProperty Count | Should -BeGreaterThan 0 + Update-OMEFirmwareDUP -Device $devices -UpdateSchedule "Preview" -DupFile "C:\Temp\BIOS_92RFG_WN64_2.11.2.EXE" | Measure-Object | Select-Object -ExpandProperty Count | Should -BeGreaterOrEqual 0 } #It ("Should try to update firmware from DUP") { diff --git a/Tests/Group.Tests.ps1 b/Tests/Group.Tests.ps1 index ef9e300..406fcf7 100644 --- a/Tests/Group.Tests.ps1 +++ b/Tests/Group.Tests.ps1 @@ -21,13 +21,13 @@ Describe "Group Tests" { } It "Should create new Group" { - New-OMEGroup -Name $TestNewGroup -Verbose - $TestNewGroup | Get-OMEGroup -Verbose | Select-Object -ExpandProperty Name | Should -Be $TestNewGroup + New-OMEGroup -Name $TestNewGroup + $TestNewGroup | Get-OMEGroup | Select-Object -ExpandProperty Name | Should -Be $TestNewGroup } It "Should edit Group name" { - $TestNewGroup | Get-OMEGroup | Edit-OMEGroup -Name $TestNewGroupEdit -Description "This is a test" -Verbose - $TestNewGroupEdit | Get-OMEGroup -Verbose | Select-Object -ExpandProperty Name | Should -Be $TestNewGroupEdit + $TestNewGroup | Get-OMEGroup | Edit-OMEGroup -Name $TestNewGroupEdit -Description "This is a test" + $TestNewGroupEdit | Get-OMEGroup | Select-Object -ExpandProperty Name | Should -Be $TestNewGroupEdit } It "Should added Devices to Group" { diff --git a/Tests/SupportAssist.Tests.ps1 b/Tests/SupportAssist.Tests.ps1 index 58dec6a..67415ca 100644 --- a/Tests/SupportAssist.Tests.ps1 +++ b/Tests/SupportAssist.Tests.ps1 @@ -25,7 +25,7 @@ Describe "Support Assist Tests" { It "Should add devices to support assist group" { $devices = $($Script:DeviceServiceTag | Get-OMEDevice -FilterBy "ServiceTag") $Script:TestSupportAssistGroupName | Get-OMEGroup | Edit-OMESupportAssistGroup -Devices $devices - Get-OMEDevice -Group $("Support Assist Group 1" | Get-OMEGroup) | Measure-Object | Select-Object -ExpandProperty Count | Should -BeGreaterThan 0 + Get-OMEDevice -Group $($Script:TestSupportAssistGroupName | Get-OMEGroup) | Measure-Object | Select-Object -ExpandProperty Count | Should -BeGreaterThan 0 } It "Should edit support assist group" {