Sample/Find-Duplicates/find-duplicates.ps1

# ------------------------------------------------------------------
# Lenovo Copyright
#
# (C) Copyright Lenovo 2024 - 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.
# ------------------------------------------------------------------

<#
- Example scripts to illustrate how to find systems managed on multiple LXCAs.
#>


using namespace System.Collections.Generic

Clear-Host
#Import-Module C:\Users\$env:USERNAME\Documents\WindowsPowerShell\Modules\LXCAPSTool\4.0.1.0\LXCAPSTool.psd1
Import-Module LXCAPSTool

Set-LXCAPSLogLevel -LogLevel Debug
Add-LXCAPSLogHeader -UserMessage "Check duplicates started on $(Get-Date)" -Identity -MachineId

. $PSScriptRoot\common\connect.ps1
. $PSScriptRoot\common\deviceManipulation.ps1

$connections = LXCAConnect -DataPath $PSScriptRoot
[List[DeviceData]] $devices = [List[DeviceData]]::new()
foreach ($con in $connections)
{
    Write-Host "connected to: $($con.Host)"
    $servers = Get-LXCAServer -Connection $con
    Write-Host "LXCA $($con.Host) contains $($servers.Count) devices"
    foreach ($server in $servers)
    {
        AddDevice -Device $server -Devices $devices -LXCAHost $con.Host
    }
}
#close connections to LXCAs
LXCADisconnect -Connections $connections

Write-Host "Managed servers across all LXCAs: $($devices.Count)"

# select multiple appearances
[List[DeviceData]] $multiple = [List[DeviceData]]::new()
RemoveSingleAppearance -InList $devices -OutList $multiple

Write-Host "Managed servers on multiple LXCAs: $($multiple.Count)"
$multiple | Format-List

#EOF