# Find machine folders with Backup subdirectories
$testPath = "\\192.168.0.6\test"

Write-Host "Searching for machine folders with Backup subdirectories in $testPath"
Write-Host ""

$machineFolders = Get-ChildItem -Path $testPath -Directory -ErrorAction SilentlyContinue

foreach ($folder in $machineFolders) {
    $backupPath = Join-Path $folder.FullName "Backup"
    if (Test-Path $backupPath) {
        Write-Host "FOUND: $($folder.Name) -> $backupPath"

        # Check if there are any files in the backup folder
        $backupFiles = Get-ChildItem -Path $backupPath -File -ErrorAction SilentlyContinue
        if ($backupFiles) {
            Write-Host "  Files: $($backupFiles.Count) files found"
            Write-Host "  Latest: $($backupFiles | Sort-Object LastWriteTime -Descending | Select-Object -First 1 | ForEach-Object { "$($_.Name) - $($_.LastWriteTime)" })"
        } else {
            Write-Host "  (Empty backup folder)"
        }
        Write-Host ""
    }
}

Write-Host "Search complete."
