> 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/fr/knowledge-base/troubleshooting-articles/test-secret-server-access-with-a-powershell-script.md).

# Tester l'accès à Secret Server avec un script PowerShell

Utilisez un script PowerShell pour tester la connectivité du client à l'API REST de Delinea Secret Server et confirmer que les recherches de secrets fonctionnent en dehors de Remote Desktop Manager.

Lorsqu'une entrée ***Delinea Secret Server*** ne peut pas s'authentifier ou ne retourne aucun secret, tester la connexion en dehors de Remote Desktop Manager montre si le problème vient du poste de travail, du réseau ou du compte Secret Server. Remote Desktop Manager communique avec Secret Server par son API REST : il demande un jeton OAuth2 à `<Secret Server URL>/oauth2/token`, puis interroge `<Secret Server URL>/api/v1/secrets`. Le script PowerShell suivant effectue les deux mêmes appels.

1. Enregistrez le code ci-dessous dans un fichier nommé `searchsecret.ps1`.
2. Remplacez les valeurs de `$url`, `$username`, `$password` et `$domain` par l'URL et les identifiants de votre Secret Server.
3. Remplacez la valeur de `$searchterm` par le nom, ou une partie du nom, d'un secret auquel vous avez accès.
4. Exécutez le script depuis le poste de travail où Remote Desktop Manager est installé.

```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 le script s'authentifie et retourne vos secrets, le poste de travail peut joindre Secret Server, et le problème se trouve dans la configuration de l'entrée dans Remote Desktop Manager. Si le script échoue, le message d'erreur indique le problème de réseau, de certificat ou de compte à résoudre du côté de Secret Server.

{% hint style="info" %}
Si votre compte Secret Server exige une authentification à deux facteurs, la demande de jeton échoue, à moins que vous n'ajoutiez le code à usage unique dans un en-tête `OTP`, comme le fait Remote Desktop Manager.
{% endhint %}

### Voir aussi

* [Paramètres de l'entrée Delinea Secret Server](/rdm/fr/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/fr/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.
