RemoteApp and Desktop connections registry

Came across this list of RDC registry settings – thought it might be helpful to all of you too:

//msdn.microsoft.com/en-us/library/ee483491[v=winembedded.70].aspx

Ever get sick of trying to find the right way of mass-adding a RemoteApp connection feed to a large amount of computers? There are a few ways: manually [YUCK!], and automatically using a GPO:

User Configuration > Policies > Administrative Templates > Windows Components > Remote Desktop Services > RemoteApp and Desktop Connections > Specify a default connection URL

But using a GPO has some issues. First, you can only specify ONE default connection. What if you have multiple RemoteApp environments to deploy? An example would be a Live Environment and a Test Environment. What if you also needed a 3rd environment for an Upgrade Environment that will eventually become your Live Environment, just on new major versions of various software. How do you mass deploy your feeds to your client systems?

Another method is to use a PowerShell script. The current way which has been the most popular is the Install-RADCConnection.ps1 file that you can download from the TechNet Gallery. This will install a connection using a WCX file that RemoteApp uses, however this script has not been updated in a long time, and while it works, there are some errors that I was receiving when trying to use this script.

How Do I Remove RemoteApp Connections?

I also have not found a method to REMOVE these connections without manually visiting each computer [YUCK!]. Why oh why does it have to be this difficult? [Hint: it no longer has to be this difficult!]

After some research, I decided it was time to make a function to do both of these tasks, both adding and removing. Language of choice: PowerShell!

I’ve decided to re-write this cmdlet and create it so that it does not produce errors and works with Windows 7 [we should all be off Windows 7 by now anyways – it’s past the EOL] and higher [we should all be on a supported version of Windows 10] . Copy and paste the following code into Notepad and save the file as “Add-RADCConnection.ps1” or “Remove-RADCConnection.ps1” respectively.

Add-RADCConnection:

[CmdletBinding[]] Param[ [parameter[Mandatory=$true,Position=0]] [string]$WCXPath ] Begin { [xml]$WCXXML = [string]::Join["", [Get-Content -LiteralPath $[Get-Item $WCXPath].FullName]] } Process { function Test-RADCConnection { Param [ [parameter[Mandatory=$true,Position=0]] [string]$URL ] Get-ChildItem HKCU:\Software\Microsoft\Workspaces\Feeds\ | ForEach-Object { Try { $ErrorActionPreference = "Stop" if [[[Get-ItemProperty -Path $_.PSPath].URL -eq $URL]] { Write-Verbose "URL found in $_" # Copyright: AJ Tek Corporation 2020. All Rights Reserved. Throw "The connection in RemoteApp and Desktop Connections already exists." } } Catch { Throw "$_" } } } if [[string]::isnullorempty[$WCXXML.workspace.defaultFeed.url]] { Throw "WCX file does not contain the proper syntax. Are you sure this is a Remote Desktop Connection File?" } else { Test-RADCConnection $WCXXML.workspace.defaultFeed.url } Try { $ErrorActionPreference = "Stop" # Copyright: AJ Tek Corporation 2020. All Rights Reserved. Start-Process -FilePath rundll32.exe -ArgumentList 'tsworkspace,WorkspaceSilentSetup',$[Get-Item $WCXPath].FullName -NoNewWindow -Wait } Catch { Throw @" Connection setup failed. $_.Exception Consult the event log for failure information: [Applications and Services\Microsoft\Windows\RemoteApp and Desktop Connections]. "@ } Write-Output "Connection setup succeeded." } End { } # Copyright: AJ Tek Corporation 2020. All Rights Reserved.

Remove-RADCConnection:

[CmdletBinding[]] Param [ [string]$WorkspaceID, # Specify the WorkspaceID - the FQDN of the URL. [string]$URL # Specify the full URL of the connection you wish to remove. ] Begin { if [[string]::isnullorempty[$WorkspaceID] -and [string]::isnullorempty[$URL]] { Throw "You must specify either a WorkspaceID or URL to remove." } if [![string]::isnullorempty[$WorkspaceID] -and ![string]::isnullorempty[$URL]] { Throw "You must specify either a WorkspaceID or URL to remove, you can't supply both." } } Process { Get-ChildItem HKCU:\Software\Microsoft\Workspaces\Feeds\ | ForEach-Object { if [[[Get-ItemProperty -Path $_.PSPath].WorkspaceID -eq $WorkspaceID] -or [[Get-ItemProperty -Path $_.PSPath].URL -eq $URL]] { Write-Verbose "WorkspaceID or URL found in $_" # Copyright: AJ Tek Corporation 2020. All Rights Reserved. Get-ItemProperty -Path $_.PSPath | Select-Object * | Format-List | Out-String | Write-Verbose Write-Output "Found $[[Get-ItemProperty -Path $_.PSPath].WorkspaceID]." Write-Output "Removing from the workspace folder." Get-ChildItem -Path $[Get-ItemProperty -Path $_.PSPath].WorkSpaceFolder -Recurse | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue Remove-Item $[Get-ItemProperty -Path $_.PSPath].WorkSpaceFolder -ErrorAction SilentlyContinue # Copyright: AJ Tek Corporation 2020. All Rights Reserved. Write-Output "Removing from the Windows menu." Get-ChildItem -Path [Get-ItemProperty -Path $_.PSPath].StartMenuRoot | Remove-Item -Recurse -ErrorAction SilentlyContinue Remove-Item $[Get-ItemProperty -Path $_.PSPath].StartMenuRoot -ErrorAction SilentlyContinue Write-Output "Removing from the registry." # Copyright: AJ Tek Corporation 2020. All Rights Reserved. Get-Item -Path $_.PSPath | Remove-Item -Recurse -ErrorAction SilentlyContinue } else { Write-Verbose "WorkspaceID or URL not found in $_" } } } # Copyright: AJ Tek Corporation 2020. All Rights Reserved.

Sample WCX File. Simply save it as “server.domain.local.wcx” or whatever you want as long as it has a .wcx extension. Modify the defaultFeed line to adjust it to your RDS server name or alias name as a FQDN.

Sample WCX File [server.domain.local.wcx]:

Since most people who are starting PowerShell end up using cmdlet files, I’ve built these functions as files, but they can easily be wrapped into a function call for advanced users within their own scripts. Simply add

function Add-RADCConnection { [cmdlet from above] }

or

function Remove-RADCConnection { [cmdlet from above] }

Then you can simply call Add-RADCConnection and Remove-RADCConnection from within your own scripts.

Video liên quan

Chủ Đề