# Test WinRM Connection to AD2
Write-Host "[INFO] Testing WinRM connection to AD2..."

# Admin account test
Write-Host "`n[TEST 1] Admin Account (INTRANET\sysadmin)"
$adminPassword = ConvertTo-SecureString "Paper123!@#" -AsPlainText -Force
$adminCred = New-Object System.Management.Automation.PSCredential("INTRANET\sysadmin", $adminPassword)

try {
    $result = Invoke-Command -ComputerName 192.168.0.6 -Credential $adminCred -ScriptBlock {
        @{
            Computer = $env:COMPUTERNAME
            Domain = $env:USERDOMAIN
            User = $env:USERNAME
            WinRM = (Get-Service WinRM).Status
        }
    } -ErrorAction Stop

    Write-Host "[SUCCESS] Connected to AD2" -ForegroundColor Green
    Write-Host "  Computer: $($result.Computer)"
    Write-Host "  Domain: $($result.Domain)"
    Write-Host "  User: $($result.User)"
    Write-Host "  WinRM Status: $($result.WinRM)"
} catch {
    Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
}

# Service account test
Write-Host "`n[TEST 2] Service Account (INTRANET\ClaudeTools-ReadOnly)"
$svcPassword = ConvertTo-SecureString "vG!UCAD>=#gIk}1A3=:{+DV3" -AsPlainText -Force
$svcCred = New-Object System.Management.Automation.PSCredential("INTRANET\ClaudeTools-ReadOnly", $svcPassword)

try {
    $result = Invoke-Command -ComputerName 192.168.0.6 -Credential $svcCred -ScriptBlock {
        @{
            Computer = $env:COMPUTERNAME
            Domain = $env:USERDOMAIN
            User = $env:USERNAME
            UserCount = (Get-ADUser -Filter * | Measure-Object).Count
        }
    } -ErrorAction Stop

    Write-Host "[SUCCESS] Connected to AD2" -ForegroundColor Green
    Write-Host "  Computer: $($result.Computer)"
    Write-Host "  Domain: $($result.Domain)"
    Write-Host "  User: $($result.User)"
    Write-Host "  AD Users Found: $($result.UserCount)"
} catch {
    Write-Host "[ERROR] $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n[INFO] Testing complete."
