Samples/E2E-hub-devices/e2eHubDeviceSample.ps1
|
# ------------------------------------------------------------------ # Lenovo Copyright # # (C) Copyright Lenovo 2026 - present. # # LIMITED AND RESTRICTED RIGHTS NOTICE: # If data or software is delivered pursuant a General Services # Administration (GSA) contract, use, reproduction, or disclosure # is subject to restrictions set forth in Contract No. GS-35F-05925. # ------------------------------------------------------------------ [CmdletBinding()] param ( # portal connection parameters [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] $PortalIP, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [pscredential]$PortalCredential, [Parameter(Mandatory = $true)] [ValidateSet("onPremises", "cloud")] $PortalType, # hub connection parameters [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] $HubIP, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [pscredential]$HubCredential, # devices connection parameters [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [pscredential]$DeviceCredential, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string[]] $DeviceIPs ) Clear-Host Import-Module LXC1PSToolkit Write-LXC1PSLogMessage -UserMessage "starting again" -Identity -MachineId . $PSScriptRoot\common\common.ps1 . $PSScriptRoot\common\hubCommon.ps1 . $PSScriptRoot\common\devices.ps1 ConnectLXC1 -PortalAddress $PortalIP ` -PortalCredential $PortalCredential ` -PortalType $PortalType # add a hub if ($(AddHub -HubIP $HubIP -HubCredential $HubCredential) -eq $false) { Write-Host "Failed to add hub." exit } # exit # discover devices. $hubID = GetHubID $discoveryJobs = DiscoverDevices -DevicesIP $DeviceIPs -ManagerID $hubID WaitForTasksToEnd -JobsToWaitFor $discoveryJobs Start-Sleep -Seconds 5 # manage devices $deviceUUIDs = GetDiscoveredDevices -ManagerIP $HubIP $manageJobs = AddDiscoveredDevices -DeviceUUIDs $deviceUUIDs ` -DeviceCredential $DeviceCredential ` -ManagerID $hubID WaitForTasksToEnd -JobsToWaitFor $manageJobs Start-Sleep -Seconds 5 # get devices inventory $devices = GetDevicesInventory Write-Host "Managed devices: $($devices.Response.results.Count)" $devices.Response.results | Format-List # powerOn devices $powerOnJobs = DevicePowerOps -Devices $devices -Action "powerOn" WaitForTasksToEnd -JobsToWaitFor $powerOnJobs Start-Sleep -Seconds 5 # restart devices $restartJobs = DevicePowerOps -Devices $devices -Action "restartNormally" WaitForTasksToEnd -JobsToWaitFor $restartJobs Start-Sleep -Seconds 5 # powerOff devices $powerOffJobs = DevicePowerOps -Devices $devices -Action "powerOffNormally" WaitForTasksToEnd -JobsToWaitFor $powerOffJobs Start-Sleep -Seconds 5 # remove devices $removeDeviceJobs = RemoveDevices -Devices $devices WaitForTasksToEnd -JobsToWaitFor $removeDeviceJobs Start-Sleep -Seconds 5 # remove manager $removeHubJob = RemoveHub WaitForTasksToEnd -JobsToWaitFor $removeHubJob Write-Host "Test completed successfully." # EOF |