Recently I wanted to make it easy for users to add a Remote Desktop Service web feed through group policies. I created a script that needs to be run in the user context.
You need to specify a URL in the script as a variable.
Feel free to use it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
Function Install-RDSWebFeed { [cmdletbinding()] Param ( [Parameter(Mandatory=$true, HelpMessage="Please provide a valid URL, example 'https://remote.something.com/RDWeb/Feed/webfeed.aspx' .")]$URL ) #Check if the RDS webfeed already exists. If(-not (Check-RDSWebFeed -URL $URL)) { Write-Output "Information: Web feed doesn't exist."; #Create the WCX file. $WCX = (Create-WCXFile -URL $URL); #Add the web feed. Start-Process -FilePath rundll32.exe -ArgumentList 'tsworkspace,WorkspaceSilentSetup',$($WCX).ToString() -Wait -NoNewWindow; #Directory of the WCX file. $Directory = $WCX -split "\\"; #Delete the WCX file. Remove-Item -Path ($Directory[0] + "\" + $Directory[1]) -Force -Confirm:$false -Recurse; } Else { Write-Output "Information: Web feed already exists."; } } Function Check-RDSWebFeed { [cmdletbinding()] Param ( [Parameter(Mandatory=$true, HelpMessage="Please provide a valid URL, example 'https://remote.something.com/RDWeb/Feed/webfeed.aspx' .")]$URL ) #Get all feeds for the current user. $Feeds = Get-Item 'HKCU:\Software\Microsoft\Workspaces\Feeds\*'; [bool]$InUse = $false; #Foreach feed. Foreach($Feed in $Feeds) { #If the feed is already in use. If($Feed.GetValue("URL") -eq "$URL") { #Set variable. $InUse = $true; } } Return $InUse; } Function Create-WCXFile { [cmdletbinding()] Param ( [Parameter(Mandatory=$true, HelpMessage="Please provide a valid URL, example 'https://remote.something.com/RDWeb/Feed/webfeed.aspx' .")]$URL ) #Construct the XML file. $XML = @" <?xml version="1.0" encoding="utf-8" standalone="yes"?> <workspace name="Company Remote Access" xmlns="http://schemas.microsoft.com/ts/2008/09/tswcx" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <defaultFeed url="$URL" /> </workspace> "@ #WCX file path. $Directory = ("C:\" + [guid]::NewGuid() +"\"); $WCX = "webfeed.wcx"; $FullPath = ($Directory + $WCX); #New folder. New-Item $Directory -Type Directory -Force | Out-Null; #Export the file. $XML | Out-File -FilePath $FullPath -Encoding utf8 -Force | Out-Null; #Return file path. Return $FullPath; } Install-RDSWebFeed -URL "https://remote.netcompany.com/RDWeb/Feed/webfeed.aspx"; |