> 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/powershell/devolutions-server-powershell/powershell-connectivity-methods-to-devolutions-server.md).

# PowerShell connectivity methods to Devolutions Server

The following methods describe how to connect to Devolutions Server using PowerShell.

### Method 1: Using Remote Desktop Manager Cmdlets

{% hint style="info" %}
This new workspace created with PowerShell will only exist in the user context it was created.
{% endhint %}

1. Follow the instructions in [Devolutions.PowerShell module](https://docs.devolutions.net/powershell/rdm-powershell/rdm-powershell-core-module/) to properly install the module.
2. Create a new Devolutions Server workspace using an [Application Key and Application Secret](https://docs.devolutions.net/server/web-interface/administration/security-management/applications/) with the following script. This script should only be used once to avoid creating many new workspaces. Replace the values of the four variables (lines 7 to 10) with your own information, then run the script.

```powershell
$dsname = "DVLS PowerShell"
$ds = Get-RDMDataSource -Name $dsname

# If the workspace doesn't exist, create it.
if ([string]::IsNullOrEmpty($ds))
{
  $dsname = "DVLS PowerShell"
  $dsurl = "https://your_dvls_url"
  $appkey = "your_appkey"
  $appsecret = "your_appsecret"

  $ds = New-RDMDataSource -DVLS -Name $dsname -Server $dsurl -ScriptingTenantID $appkey -ScriptingApplicationPassword $appsecret -SetDatasource -WarningAction SilentlyContinue
  Set-RDMDataSource $ds
}

Set-RDMCurrentDataSource $ds
```

3. To connect to the workspace, use these lines in all your scripts.

```powershell
$dsname = "DVLS PowerShell"
$ds = Get-RDMDataSource -Name $dsname
Set-RDMCurrentDataSource $ds
```

### Method 2: Using Devolutions Server Cmdlets

1. Follow the instructions in [Devolutions.PowerShell module](https://docs.devolutions.net/powershell/rdm-powershell/rdm-powershell-core-module/) to properly install the module.
2. The script expects an [Application Key and Application Secret](https://docs.devolutions.net/server/web-interface/administration/security-management/applications/) and URL to be defined in environment variables. Since storing credentials in scripts is frowned upon, adapt a local file for running your own tests.

```powershell
$env:DS_URL= "https://localhost/dvls"
$env:DS_USER = "your_appkey"
$env:DS_PASSWORD = "your_appsecret"
```

3. The following sample script can be used to connect using an [Application Key and Application Secret](https://docs.devolutions.net/server/web-interface/administration/security-management/applications/).

```powershell
[string]$Username = $env:DS_USER
[string]$Password = $env:DS_PASSWORD
[string]$DVLSUrl = $env:DS_URL

[securestring]$SecPassword = ConvertTo-SecureString $Password -AsPlainText -Force
[pscredential]$Creds = New-Object System.Management.Automation.PSCredential ($Username, $SecPassword)

$Response = New-DSSession -Credential $Creds -BaseURI $DVLSUrl -AsApplication
```

4. Once the script is completed and all tasks are fulfilled, close the session using the `Close-DSSession` cmdlet.

```powershell
Close-DSSession | out-null
Write-Output " "
Write-Output "...Done!"
Write-Output " "
```

### See also

* [Manage application identities](https://docs.devolutions.net/cloud/web-interface/administration/management/application-users/manage-application-users/)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.devolutions.net/powershell/devolutions-server-powershell/powershell-connectivity-methods-to-devolutions-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
