Microsoft OneDrive - AutoConfigure/AutoLogin

HNTIT
Contributor II

We are looking to find a way to have OneDrive Configured as the user at Initial Login.

On A PC, when a Domain User Logs In, OneDrive automatically gets Logged in as the Users O365 OneDrive For Business, we are trying to replicate this one MAC's

7 REPLIES 7

B_Johnston
New Contributor II

I am also wondering how this is done. The only thing I can think of is somehow utilizing NoMAD or Jamf Connect (Azure AD login) to achieve this. A normal AD login for Mac problem won't be able to achieve this.

rickgmac
Contributor

From Memory they discussed this at the managing office session at JNUC 2018.

It can be done from a config profile, or it is coming very soon.

HNTIT
Contributor II

The Redirection part i now do in a Script.

Variable 4 is The OneDrive Folder Name. eg OneDrive for Business yourcompnyname
Variable 5 is whether to simply "Report" or take "Action"

#!/bin/bash

####################################################################################################
#
# Description
#
# Script to Check and/or Modify Users OneDrive Settings
#
####################################################################################################
#
#   Setting Variables
#
####################################################################################################
#
UserName="$3"
ODFolderName="$4"
Act=$5
#
Action=$(echo $Act | tr “[A-Z]” “[a-z]”)
#
ODFolder="/Users/$UserName/$ODFolderName"
#
Desktop=$(ls -n "/Users/$UserName/" | grep "Desktop" | awk '{print $9,$10,$11,$12,$13,$14}')
#
Documents=$(ls -n "/Users/$UserName/" | grep "Documents" | awk '{print $9,$10,$11,$12,$13,$14}')
#
ExitCode=0
#
####################################################################################################
# 
# Begin Processing
#
####################################################################################################
#
# Checking If Action Variable has been set
#
####################################################################################################

# Outputting a Blank Line for Reporting Purposes
echo

if [ "$Action" == "report" ]
    then
        # Outputting a Blank Line for Reporting Purposes
        echo

        Echo Script Action is set to Report Only
    else
        if [ "$Action" == "action" ]
            then
                # Outputting a Blank Line for Reporting Purposes
                echo

                Echo "Script Action is set to Take Action if needed"
        else
            # Outputting a Blank Line for Reporting Purposes
            echo

            echo "Report / Action Variable Not Set For This Script"

            # Outputting a Blank Line for Reporting Purposes
            echo

            Echo 'Ending Script "ZZ 17 - Global Settings - OneDrive Settings Script" '
            exit 1
        fi
fi

# Outputting a Blank Line for Reporting Purposes
echo

echo -------------------------------------------------------------------------------

# Outputting a Blank Line for Reporting Purposes
echo

####################################################################################################
#
# Checking If OneDrive Folder Exists
#
####################################################################################################

echo Checking if OneDrive Folder Exists

if ! [ -d "$ODFolder" ]
    then
        # Outputting a Blank Line for Reporting Purposes
        echo

        echo Folder '"'$ODFolder'"' Does not exist.
        echo OneDrive Not Set Up For This User.

        if [ "$Action" == "report" ]
            then
                # Outputting a Blank Line for Reporting Purposes
                echo

                Echo 'Ending Script "ZZ 17 - Global Settings - OneDrive Settings Script" '
                exit 1
        fi

        if [ "$Action" == "action" ]
            then
                # Outputting a Blank Line for Reporting Purposes
                echo
                echo No Actions set for this scenario

                # Outputting a Blank Line for Reporting Purposes
                echo

                Echo 'Ending Script "ZZ 17 - Global Settings - OneDrive Settings Script" '
                exit 2
        fi

    else
        # Outputting a Blank Line for Reporting Purposes
        echo

        echo Folder '"'$ODFolder'"' Exists.
        echo OneDrive must be Set Up For This User.
        echo Continuing Checks
        # Outputting a Blank Line for Reporting Purposes
        echo

        echo -------------------------------------------------------------------------------

        # Outputting a Blank Line for Reporting Purposes
        echo

####################################################################################################
#
# Checking If Desktop Folder in OneDrive
#
####################################################################################################

        echo "Checking Existence of Desktop Folder in OneDrive"

        if [ "$Desktop" == "Desktop -> $ODFolder/Desktop" ]
            then 
                # Outputting a Blank Line for Reporting Purposes
                echo

                echo Desktop Folder is a Symlink to..
                echo $ODFolder/Desktop
                echo Desktop Redirection into OneDrive must be Set Up For This User.

               # Outputting a Blank Line for Reporting Purposes
                echo
        fi

        if [ "$Desktop" == "Desktop     " ]
            then 
                # Outputting a Blank Line for Reporting Purposes
                echo

                echo Desktop is an Actual Folder, Desktop Redirection into OneDrive must not be configured 

                if [ "$Action" == "report" ]
                    then
                        # Outputting a Blank Line for Reporting Purposes
                        echo

                        ExitCode=3
                fi

                if [ "$Action" == "action" ]
                    then
                        if ! [ -d "$ODFolder"/Desktop ]
                            then
                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo OneDrive Folder '"'Desktop'"' Does not exist.
                                echo OneDrive Desktop not Set Up For This User.

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Moving Desktop Files and Folders into OneDrive
                                mv "/Users/$UserName/Desktop" "$ODFolder"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Creating Desktop Link into OneDrive Folder  
                                ln -s "$ODFolder"/Desktop "/Users/$UserName/Desktop"                

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Desktop Link to OneDrive"
                                chown -R $UserName "/Users/$UserName/Desktop"
                                chmod -R 755 "/Users/$UserName/Desktop"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Desktop Files and Folders in OneDrive"
                                chown -R $UserName "$ODFolder"/Desktop
                                chmod -R 755 "$ODFolder"/Desktop

                                # Outputting a Blank Line for Reporting Purposes
                                echo
                            else
                                # Outputting a Blank Line for Reporting Purposes
                                echo
                                echo OneDrive Folder '"'Desktop'"' Already Exists but is not linked.

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Copying Desktop Files and Folders into OneDrive
                                cp -R "/Users/$UserName/Desktop" "$ODFolder"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Moving Desktop Files and Folders to Desk-Old, Just Incase.
                                mv "/Users/$UserName/Desktop" "/Users/$UserName/Desk-Old"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Hiding Desk-Old, so it does not get used.
                                chflags hidden "/Users/$UserName/Desk-Old"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Desk-Old"
                                chown -R $UserName "/Users/$UserName/Desk-Old"
                                chmod -R 755 "/Users/$UserName/Desk-Old"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Creating Desktop Link into OneDrive Folder  
                                ln -s "$ODFolder"/Desktop "/Users/$UserName/Desktop"                

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Desktop Link to OneDrive"
                                chown -R $UserName "/Users/$UserName/Desktop"
                                chmod -R 755 "/Users/$UserName/Desktop"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Desktop Files and Folders in OneDrive"
                                chown -R $UserName "$ODFolder"/Desktop
                                chmod -R 755 "$ODFolder"/Desktop

                                # Outputting a Blank Line for Reporting Purposes
                                echo
                         fi
                fi
        fi

        echo -------------------------------------------------------------------------------

        # Outputting a Blank Line for Reporting Purposes
        echo

####################################################################################################
#
# Checking If Documents Folder in OneDrive
#
####################################################################################################

        echo "Checking Existence of Documents Folder in OneDrive"

        if [ "$Documents" == "Documents -> $ODFolder/Documents" ]
            then 
                # Outputting a Blank Line for Reporting Purposes
                echo

                echo Documents Folder is a Symlink to..
                echo $ODFolder/Documents
                echo Documents Redirection into OneDrive must be Set Up For This User.

               # Outputting a Blank Line for Reporting Purposes
                echo
        fi

        if [ "$Documents" == "Documents     " ]
            then 
                # Outputting a Blank Line for Reporting Purposes
                echo

                echo Documents is an Actual Folder, Documents Redirection into OneDrive must not be configured 

                if [ "$Action" == "report" ]
                    then
                        # Outputting a Blank Line for Reporting Purposes
                        echo

                        ExitCode=4
                fi

                if [ "$Action" == "action" ]
                    then
                        if ! [ -d "$ODFolder"/Documents ]
                            then
                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo OneDrive Folder '"'Documents'"' Does not exist.
                                echo OneDrive Documents not Set Up For This User.

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Moving Documents Files and Folders into OneDrive
                                mv "/Users/$UserName/Documents" "$ODFolder"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Creating Documents Link into OneDrive Folder  
                                ln -s "$ODFolder"/Documents "/Users/$UserName/Documents"                

                                echo "Setting Permissions on Documents Link to OneDrive"
                                chown -R $UserName "/Users/$UserName/Documents"
                                chmod -R 755 "/Users/$UserName/Documents"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Documents Files and Folders in OneDrive"
                                chown -R $UserName "$ODFolder"/Documents
                                chmod -R 755 "$ODFolder"/Documents

                                # Outputting a Blank Line for Reporting Purposes
                                echo
                            else
                                # Outputting a Blank Line for Reporting Purposes
                                echo
                                echo OneDrive Folder '"'Documents'"' Already Exists but is not linked.

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Copying Documents Files and Folders into OneDrive
                                cp -R "/Users/$UserName/Documents" "$ODFolder"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Moving Desktop Files and Folders to Doc-Old, Just Incase.
                                mv "/Users/$UserName/Documents" "/Users/$UserName/Doc-Old"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Hiding Doc-Old, so it does not get used.
                                chflags hidden "/Users/$UserName/Doc-Old"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Doc-Old"
                                chown -R $UserName "/Users/$UserName/Doc-Old"
                                chmod -R 755 "/Users/$UserName/Doc-Old"

                                 # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo Creating Documents Link into OneDrive Folder  
                                ln -s "$ODFolder"/Documents "/Users/$UserName/Documents"                

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Documents Link to OneDrive"
                                chown -R $UserName "/Users/$UserName/Documents"
                                chmod -R 755 "/Users/$UserName/Documents"

                                # Outputting a Blank Line for Reporting Purposes
                                echo

                                echo "Setting Permissions on Documents Files and Folders in OneDrive"
                                chown -R $UserName "$ODFolder"/Documents
                                chmod -R 755 "$ODFolder"/Documents

                                # Outputting a Blank Line for Reporting Purposes
                                echo
                         fi
                fi
        fi
fi

echo -------------------------------------------------------------------------------

# Outputting a Blank Line for Reporting Purposes
echo

Echo 'Ending Script "ZZ 17 - Global Settings - OneDrive Settings Script" '
exit $ExitCode

szultzie
Contributor II

Hi @HNTIT , So im looking at your script, and it looks liek somthign i need for our environment.

Im not a big scripter so i had a few questions, How does $3 variable get populated?

Is this designed to run automatically on each users log in?

At first i need a EA to check to see if the one drive folder exisits for a user and report on it, is there a way to midify this script to do that?

-Peter

samspade21
New Contributor

We have taken some of your script and added it to our MacOS OneDrive KFM tool. Thank you.
https://github.com/synapsepd/MacOS-OneDrive-KFM

DennisMX
Contributor II

Thanks for the script.
Works like a charm.

I changed the Username variable.
$3 picks the Jamf connect username including @company.com
So I use: UserName=$(/usr/bin/stat -f%Su /dev/console)

Still the question remains: How do you configure Automatic login?

caffine247
New Contributor III

Take a look at (https://docs.microsoft.com/en-us/onedrive/deploy-and-configure-on-macos)