Microsoft Remote Desktop Connections

DougE
New Contributor III

I manage an environment with about a 60/40 mix of Macs to PCs. Many of those PCs could be replaced with Macs, but the users need to either run windows programs or connect to Windows VMs.

I have had good success with Microsoft Remote Desktop, but one tecious process is setting up the connections. We have to do that manually. I did see the article about scripting this and deploying it via Policy:
https://macmule.com/2013/10/22/how-to-create-a-microsoft-remote-desktop-8-connection/

Being new to Jamf I'm not sure why that isn't working for me. I can create the script, set up the policy, get the policy to run without error, but the connection settings are not written to the plist file. Adding and editing connections manual works just fine. 1a8b056bd7274461bec9fb0c75e340b8

12 REPLIES 12

BaddMann
Contributor

looks like the script is expecting a username as parameter 8.
If I remember correctly all casper scripts insert the username in parameter 3.
If you want to use this with casper you are going to have to remove all the parameter checks or you are going to have to move them into the correct locations and actually have the option to assign them at run with casper remote.

The parameter in question:

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 8 AND, IF SO, ASSIGN TO "userName"
if [ "$8" != "" ] && [ "$userName" == "" ]; then
    userName=$8
elif [ -z "$8" ]; then
    echo "No username given.. Getting username of logged in user..."
    userName=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
fi

https://github.com/macmule/Create-a-Microsoft-Remote-Desktop-8-Connection/blob/master/Create-a-Microsoft-Remote-Desktop-8-Connection.sh

Good Luck

BaddMann
Contributor

Duplicate Post

BaddMann
Contributor

Anyway just add -x to the end of sh.
It will make the log verbose every command before executing it in the log.

#!/bin/sh -x

I often use it to debug my scripts

gmarnin
New Contributor III

I use this script to setup the connections https://github.com/gmarnin/Mac-Scripts/blob/master/RDP%20Connection%20Script.sh

I'm not a JAMF shop so I'm not sure if you would need to make changes to make it work.

stevewood
Honored Contributor II
Honored Contributor II

@DougE I have a post about this on my blog:

Remote Desktop Bookmarks

I've been using that method for a couple years now.

DougE
New Contributor III

Sorry for the late response, other projects sidelined this one for a few weeks. Thanks for the tips and help. I'll look into these options and report back what worked for us and anything else that may prove helpful for others.

bmagistro
New Contributor II

Sorry for waking up an older thread, but have any of you found a way to do something similar with version 10? From what I've been able to find, they shifted to a sqlite database that is protected (technet comments).

talkingmoose
Moderator
Moderator

It's good to revisit an issue every once in a while. Back in November, Microsoft introduced a new scripting feature for Remote Desktop. I get my app from the Mac App Store. It's version 10.2.4 from December 2018.

You can run this command to get help with the new command line tool.

'/Applications/Microsoft Remote Desktop.app/Contents/MacOS/Microsoft Remote Desktop' --script help

It'll return something like this:

2019-01-09 13:43:48.386 Microsoft Remote Desktop[94785:2744987] ADAL version 2.7.6
Usage:

  --script <module> <parameters>

  Modules:

    bookmark  Create, edit or delete a connection bookmark.
    feed      Subscribe to a resource feed, or edit or delete a subscription.
    gateway   Create, edit or delete a Remote Desktop gateway.

  To get help for a specific module:

    --script <module> help

  Examples:

    --script bookmark help
    --script feed help
    --script gateway help

If you have detailed questions or need clarification for something, I encourage you to hop into MacAdmins Slack (signup) and join the #microsoft-rdc channel. Developers from Microsoft are interacting with us directly there and taking feedback.

ThijsX
Valued Contributor
Valued Contributor

@talkingmoose Nice to know!

In our environment we have task schedulers that run many Powershell scripts, one of those automated recurring scripts is one thats pulls down all our servers living in a specific OU in AD, and based on that creates a .RDP file with specific settings for every server. and when thats there, we can import al those .RDP files. You can schedule this so when a new server pop's up a new .RDP file is created.

Very basic, but hey it works.

  • In the searchbase fill in your variables.
$serverlist = get-adcomputer -filter * -SearchBase 'OU=Servers,OU=**,DC=**,DC=**,DC=**,DC=**' -properties name |select-object name


foreach ($servername in $serverlist){
$servername = $servername.name
$filecontent = "
gatewaybrokeringtype:i:0
use redirection server name:i:0
disable themes:i:0
disable cursor setting:i:0
disable menu anims:i:1
remoteapplicationcmdline:s:
audiocapturemode:i:0
prompt for credentials on client:i:0
remoteapplicationprogram:s:
gatewayusagemethod:i:2
screen mode id:i:2
use multimon:i:0
authentication level:i:0
desktopwidth:i:0
desktopheight:i:0
redirectclipboard:i:1
loadbalanceinfo:s:
enablecredsspsupport:i:0
promptcredentialonce:i:0
redirectprinters:i:0
autoreconnection enabled:i:1
administrative session:i:0
redirectsmartcards:i:1
authoring tool:s:
alternate shell:s:
remoteapplicationmode:i:0
disable full window drag:i:1
gatewayusername:s:
shell working directory:s:
audiomode:i:0
username:s:
allow font smoothing:i:1
connect to console:i:0
gatewayhostname:s:
drivestoredirect:s:
session bpp:i:32
disable wallpaper:i:0
gatewayaccesstoken:s:
Prompt for Credentials on Client:i:0
full address:s:$servername
"| Out-File -FilePath FILEPATH$servername.rdp


}

talkingmoose
Moderator
Moderator

@txhaflaire, for a large number of servers, you may be interested in the feed feature if you're not already using it. This was new to me a few months ago. It's possible to point to a URL to get a list of server connections. Just one place to maintain.

GregE
Contributor

Thought I'd post our updated script. We have been using the excellent one that Steve Wood provided a few years ago now and with some help from the Slack Channel we've got app streaming working with MRD 10.

#!/bin/sh
# get the cli executable
cli="/Applications/Microsoft Remote Desktop.app/Contents/MacOS/Microsoft Remote Desktop"

LOGPATH='/private/tmp'

# grab the logged in username
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

# global settings
myUUID=`uuidgen`
hostAddress="*yourserveraddress*"

# variable settings
friendlyName="*title you want to appear*"
remoteappprogram="*c:locationofprogramonserver.exe*"

# deploy the above variables
sudo -u $loggedInUser "$cli" --script bookmark write "$myUUID" --hostname "$hostAddress" 
     --friendlyname "$friendlyName" 
     --remoteappprogram "$remoteappprogram" 
     --redirectprinters true 
     --username "$loggedInUser"

sudo touch /Library/Application Support/JAMF/Receipts/MRD_*appname*_11092019.pkg

GregE
Contributor

.plist has also been relocated to ~/Library/Containers/com.microsoft.rdc.macos/Data/Library/Preferences/com.microsoft.rdc.macos.plist (essentially the same but with macos in the folder name now).