The following methods describe how to connect to Devolutions Server using PowerShell.
Method 1: Using Remote Desktop Manager Cmdlets
This new data source created with PowerShell will only exist in the user context it was created.
- Follow the instructions in Devolutions.PowerShell Core Module to properly install the module.
- Create a new Devolutions Server data source using an Application Key and Application Secret with the following script. This script should only be used once to avoid creating many new data sources. Replace the values of the four variables with your own information, then run the script.
$dsname = "DVLS PowerShell"
$dsurl = "https<area>://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
- To connect to the data source, use these lines in all your scripts.
$dsname = "DVLS PowerShell"
$ds = Get-RDMDataSource -Name $dsname
Set-RDMCurrentDataSource $ds
Method 2: Using Devolutions Server Cmdlets
- Follow the instructions in Devolutions.PowerShell Core Module to properly install the module.
- The script expects an Application Key and Application Secret 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.
$env:DS_URL= "http<area>://localhost/dvls"
$env:DS_USER = "your_appkey"
$env:DS_PASSWORD = "your_appsecret"
- The following sample script can be used to connect using an Application Key and Application Secret.
[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
- Once the script is completed and all tasks are fulfilled, close the session using the
Close-DSSession
cmdlet.
Close-DSSession | out-null
Write-Output " "
Write-Output "...Done!"
Write-Output " "