$password = ConvertTo-SecureString 'Paper123!@#' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('INTRANET\sysadmin', $password)

Write-Host "[OK] Mounting AD2 C$ share..."
New-PSDrive -Name AD2 -PSProvider FileSystem -Root "\\192.168.0.6\C$" -Credential $cred -ErrorAction Stop | Out-Null

Write-Host "[OK] Checking testdatadb..."
if (Test-Path "AD2:\Shares\testdatadb") {
    Write-Host "  [FOUND] testdatadb exists"

    Write-Host "`n[OK] Top-level contents:"
    Get-ChildItem "AD2:\Shares\testdatadb" | Select-Object Mode, Name, Length

    Write-Host "`n[OK] Database folder contents:"
    if (Test-Path "AD2:\Shares\testdatadb\database") {
        Get-ChildItem "AD2:\Shares\testdatadb\database" | Select-Object Mode, Name, Length
    }

    Write-Host "`n[OK] Retrieving import.js..."
    if (Test-Path "AD2:\Shares\testdatadb\database\import.js") {
        $importJs = Get-Content "AD2:\Shares\testdatadb\database\import.js" -Raw
        $importJs | Out-File "D:\ClaudeTools\import-js-retrieved.js" -Encoding UTF8
        Write-Host "  [OK] Saved to D:\ClaudeTools\import-js-retrieved.js"
        Write-Host "  [INFO] File size: $($importJs.Length) bytes"
    }

    Write-Host "`n[OK] Checking for database file..."
    $dbFiles = Get-ChildItem "AD2:\Shares\testdatadb" -Recurse -Include "*.db","*.sqlite","*.sqlite3" -ErrorAction SilentlyContinue
    if ($dbFiles) {
        Write-Host "  [FOUND] Database files:"
        $dbFiles | Select-Object FullName, Length
    } else {
        Write-Host "  [INFO] No .db or .sqlite files found"
    }

} else {
    Write-Host "  [NOT FOUND] testdatadb does not exist"
}

Remove-PSDrive -Name AD2
Write-Host "`n[OK] Done"
