> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/rdm/es/knowledge-base/troubleshooting-articles/test-secret-server-access-with-a-powershell-script.md).

# Probar el acceso a Secret Server con un script de PowerShell

Use un script de PowerShell para probar la conectividad del cliente con la API REST de Delinea Secret Server y confirmar que las búsquedas de secretos funcionan fuera de Remote Desktop Manager.

Cuando una entrada ***Delinea Secret Server*** no puede autenticarse o no devuelve ningún secreto, probar la conexión fuera de Remote Desktop Manager muestra si el problema procede de la estación de trabajo, de la red o de la cuenta de Secret Server. Remote Desktop Manager se comunica con Secret Server a través de su API REST: solicita un token OAuth2 de `<Secret Server URL>/oauth2/token` y, a continuación, consulta `<Secret Server URL>/api/v1/secrets`. El siguiente script de PowerShell realiza las mismas dos llamadas.

1. Guarde el código siguiente en un archivo llamado `searchsecret.ps1`.
2. Sustituya los valores de `$url`, `$username`, `$password` y `$domain` por la URL y las credenciales de su Secret Server.
3. Sustituya el valor de `$searchterm` por el nombre, o parte del nombre, de un secreto al que pueda acceder.
4. Ejecute el script desde la estación de trabajo en la que está instalado Remote Desktop Manager.

```powershell
$url = 'https://mysecretserver/SecretServer'
$username = 'myusername'
$password = 'mypassword'
$domain = 'mydomain'   # leave blank for local users

$searchterm = 'VPN'

# Request an OAuth2 token with the username and password.
$loginName = if ($domain) { "$domain\$username" } else { $username }
$body = @{
    username   = $loginName
    password   = $password
    grant_type = 'password'
}

try {
    $token = (Invoke-RestMethod -Method Post -Uri "$url/oauth2/token" -Body $body -ContentType 'application/x-www-form-urlencoded').access_token
}
catch {
    Write-Host 'Authentication failed:' $_.Exception.Message
    exit
}

# Search secrets with the search term, authenticating with the token.
Write-Host 'Searching for:' $searchterm
$headers = @{ Authorization = "Bearer $token" }
$query = 'filter.searchText=' + [uri]::EscapeDataString($searchterm)

try {
    $result = Invoke-RestMethod -Method Get -Uri "$url/api/v1/secrets?$query" -Headers $headers
    Write-Host 'Got search results:' $result.records.Count
    $result.records | ForEach-Object { Write-Host 'SecretId:' $_.id '  Name:' $_.name '  FolderId:' $_.folderId }
}
catch {
    Write-Host 'Search failed:' $_.Exception.Message
}
```

Si el script se autentica y devuelve sus secretos, la estación de trabajo puede alcanzar Secret Server, y el problema está en la configuración de la entrada en Remote Desktop Manager. Si el script falla, el mensaje de error señala el problema de red, de certificado o de cuenta que hay que resolver en el lado de Secret Server.

{% hint style="info" %}
Si su cuenta de Secret Server requiere autenticación de dos factores, la solicitud de token falla a menos que añada el código de un solo uso en un encabezado `OTP`, como hace Remote Desktop Manager.
{% endhint %}

### Véase también

* [Configuración de la entrada Delinea Secret Server](/rdm/es/knowledge-base/knowledge-base-articles/delinea-secret-server-entry-settings.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/rdm/es/knowledge-base/troubleshooting-articles/test-secret-server-access-with-a-powershell-script.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
