Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Run command only if user logged in and has OneDrive configured

Here's a problem I'm having that I'm hoping someone can help me figure out. We're in the process of migrating to Office 365 and want to sync OneDrive with a mapped network drive. There's no way to do that other than to use a symbolic link; which works sufficiently. When you do that, though, OneDrive does not sync correctly on it's own after the initial sync when the program is opened. This has reduced me to try to develop a PDQ package that will terminate OneDrive and then reopen it.

I have successfully made the package with the commands to terminate and to quietly reopen OneDrive. If a user is not logged in when the package deploys it would error out so I have it set to run only if a user is logged on. Again, that works fine. But, not all users that might log in to a computer on the domain will have OneDrive configured. I need to find a way if possible to only run the package if a user is logged on AND that user has OneDrive configured.

Which brings me to the issue I'm having. If OneDrive is configured, there is a OneDrive folder in C:\Users\%username%\Microsoft. If not configured, no folder is present. I am trying to use the File Exists condition to determine if Onedrive.exe exists in C:\Users\%username%\Microsoft\OneDrive, but am having no success. I have also tried the path %LocalAppData%\Microsfot\OneDrive but that is not working either.

I am running the package as Logged on User instead of Deploy User for the profile path reason. Is this not supported or am I doing it incorrectly somehow?

0

Comments

9 comments
Date Votes
  • Also, OneDrive.exe exists at the root of the OneDrive folder, but when it wasn't working I tried selecting the Include Subdirectories box as shown in the screenshot, but it had no effect. Wanted to clarify in case anyone noticed.

    0
  • I believe Conditions are evaluated with the Deploy user, not the logged on user. I recommend using a PowerShell step to check for that folder instead.

    if ( Test-Path "$env:LOCALAPPDATA\Microsoft\OneDrive\OneDrive.exe" ) {

    Put the rest of your script here

    }
    0
  • Thank you. That allowed me to run the taskkill command to close OneDrive, but I am not well versed in powershell and am struggling with the correct PS syntax to reopen it.

    My command to run in a batch file is: start %LocalAppData%\Microsoft\OneDrive\OneDrive.exe /background

    The /background prevents an Windows Explorer window from opening. Any advice on how to get it to run correctly?

     

     

    0
  • Start-Process -FilePath "$env:LOCALAPPDATA\Microsoft\OneDrive\OneDrive.exe" -ArgumentList "/background"
    0
  • Thank you so much! That did the trick and it is working just as I want it to now.

    0
  • A follow up question. While my ps script is working now, PDQ shows the deploy as successful whether the command is executed or not. I am trying to modify the package to return exit code 0 if the command is executed and 1 if not. The console now shows 'Powershell script returned error code 1', but is still reporting the deploy as successful even though I only have 0 defined as a success code.

    Here is my script:

    if ( Test-Path "$env:LOCALAPPDATA\Microsoft\OneDrive\OneDrive.exe" ) {  
    Taskkill /IM OneDrive.exe /F
    Start-Process -FilePath "$env:LOCALAPPDATA\Microsoft\OneDrive\OneDrive.exe" -ArgumentList "/background"
    Exit 0
    } Else {
    Exit 1
    }

     

    What am I doing wrong?

    0
  • Just to clarify, your Status shows Successful even though Error shows "Powershell script returned error code 1"?

    Are you running this as a PowerShell or Install step?

    Are you running Deploy 15.3.0.0?

    0
  • Colby,

    It's being run as a powershell step and I am running 15.3.0.0. The job itself shows a status of successful with no error.

    If I click on the 1 of 1 Steps link the job log there shows error:

     

    0
  • I figured it out. Somehow I overlooked that the Options tab Error Mode field was set to Continue instead of Stop Deployment with Error. Working as expected now.

    0