Created
May 23, 2019 04:22
-
-
Save talkingmoose/cccbc4b9fde9651fbcd6b09b9f806b76 to your computer and use it in GitHub Desktop.
Creates a user account in Microsoft Remote Desktop 10 under Preferences > User Accounts. Modify the necessary items under the "set the keychain item attributes" and run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # set the keychain item attributes | |
| account=$( uuidgen ) | |
| accountName="serveradmin" # aka label | |
| accountPassword="MySecretPassword" | |
| applicationPath="/Applications/Microsoft Remote Desktop.app" | |
| friendlyName="Server Administrator" | |
| service="com.microsoft.rdc.macos" | |
| # stop the script if Remote Desktop is running | |
| if [ $( /usr/bin/pgrep "Microsoft Remote Desktop" ) ]; then | |
| echo "Microsoft Remote Desktop is currently running. Quit the application and try again." | |
| exit 1 | |
| fi | |
| # get index number of last user account | |
| lastUserAccount=$( /usr/bin/sqlite3 "$HOME/Library/Containers/com.microsoft.rdc.macos/Data/Library/Application Support/com.microsoft.rdc.macos/com.microsoft.rdc.application-data.sqlite" "SELECT Z_PK FROM ZCREDENTIALENTITY ORDER BY Z_PK DESC LIMIT 1" ) | |
| # create the keychain item | |
| /usr/bin/security add-generic-password \ | |
| -a "$account" \ | |
| -l "$accountName" \ | |
| -w "$accountPassword" \ | |
| -T "$applicationPath" \ | |
| -s "$service" | |
| # modify the SQLite database to reference the keychain item | |
| /usr/bin/sqlite3 "$HOME/Library/Containers/com.microsoft.rdc.macos/Data/Library/Application Support/com.microsoft.rdc.macos/com.microsoft.rdc.application-data.sqlite" "INSERT INTO ZCREDENTIALENTITY (Z_PK, Z_ENT, Z_OPT, ZNILPASSWORD, ZFRIENDLYNAME, ZID, ZUSERNAME) VALUES ($((lastUserAccount+1)), 4, 1, 0, '$friendlyName', '$account', '$accountName' )" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment