PowerShell CmdLet to check OneDrive for Business or OneDrive Personal Status


 

My good friend Neil Hodgkinson gave me a challenge: some partners and companies were asking him how to verify the status of OneDrive. He gave me the idea to check the icon of the OneDrive folder and depending on the icon, tell the status. I created a proof-of-concept and then helped some folks at Microsoft Consulting Services to have a PowerShell cmdlet to do so. Not being enough the status of OneDrive using the regular OneDrive synchronization, I also included the status of OneDrive when synchronized via Groove (yes, people still use it).

The project is open source and available in GitHub. To get only the PowerShell cmdlet, download OneDriveLib.dll here. License is MIT and can be found here. It is an open source project so it is not entitled for Microsoft support but I will do my best to respond questions in this post. Just ask them in comments.

 

How to use:

  • Open PowerShell is normal mode (it will not work in Elevated mode for OneDrive own design)
  • Import the module OneDriveLib.dll
  • Run Get-ODStatus

 

Syntax:

Get-ODStatus [-Type <type-pattern>] [-ByPath <path>]

 

Where:

-Type <type-pattern> let you filter by OneDrive type (e.g. Personal or Business) [optional]

-ByPath <path> if the folder information is not in the registry you can test a particular folder (this form will return only a status string)

 

Examples:

Get-ODStatus –Type Business

Get-ODStatus –ByPath c:\user\rodneyviana\onedrive

 

Example of output

PS C:\ODTool>; Import-Module OneDriveLib.dll
 
PS C:\ODTool>; Get-ODStatus
 
 
StatusString : UpToDate
LocalPath    : E:\MicrosoftOnedrive\OneDrive - Contoso
UserSID      : S-1-5-21-124012345-708012345-1543012345-802000
UserName     : CONTOSO\rodneyviana
ServiceType  : Business1
 
StatusString : UpToDate
LocalPath    : D:\Onedrive
UserSID      : S-1-5-21-124012345-708012345-1543012345-802000
UserName     : CONTOSO\rodneyviana
ServiceType  : Personal
Comments (40)

  1. Saqlain Tahir says:

    It’s great and will be very helpful for my customers

  2. Thanks, great to have this. Just as a side note, in order to use the DLL, make sure you UNBLOCK it via the properties of the file. Basically right click, select unblock and apply. Close and re-open your PowerShell and then follow the instructions.

    1. Rocky says:

      Scott, thanks for the tip. I just ran import-module and got the error saying the dll is missing. Doh!

  3. Scott says:

    What is it’s intended return for Work Folders?

  4. Gareth says:

    Hey, This is exactly what we are looking for. However as novices require a little guidance on the setup? Ive downloaded the full project but dont understand where to save the files to and successfully run the commands. Please help!

  5. Dan says:

    Thanks for this. Can you help provide more details on StatusString, like what would be the expected output if user are syncing their Personal OneDrive on their PC or laptop?

    1. Possible values:
      public enum ServiceStatus
      {
      Error,
      Shared,
      SharedSync,
      UpToDate,
      Syncing,
      ReadOnly,
      NotInstalled
      }

  6. Sasa says:

    I use that module and got status for all client but several. On several pc’s I don’t get any results. (win10). Do you have any idea?

    1. You may need to unblock the DLL.
      Unzip
      In Windows Explorer see the DLL properties
      Check ‘Unblock’

  7. Roberto says:

    Is great however Get-ODstatus only show me personal information and not the business even if I use the -Type. When I specify -ByPath I can have the business information. Do you have any idea what can be the cause ?

    1. It will show personal (OneDrive) and Business (OneDrive for Business). Per OneDrive design it will only show information about your user. Also per design it will not work if you run in elevated privileges. Not my rules.

  8. Chris Webb says:

    So how are you guys going about deploying this? I’m assuming every machine has to have this dll and the command run on it?

    1. Hi Chris,

      You are correct. It has to be local and it has to run in user context. It will not work in non-interactive way (like a service for example) and it will not work in elevated privileges. OneDrive requirements.

  9. Stuart Landells says:

    Has anyone been able to apply where-object filtering (or any other) to the output?
    I’ve tried all sorts of things and must just be having a moment, or it simply doesn’t work. I either get all results back regardless of the filter, or no results back. Nothing in between.
    There are some Dropbox accounts on the machines being scanned, and it actually picks those up too 🙂
    Get-ODStatus –Type Business | where {$_.LocalPath -like ‘*OneDrive*’} = Everything Business
    Get-ODStatus –Type Business | where {$_.ServiceType -like ‘Business1’} = Everything Business
    Get-ODStatus –Type Business | where {$_.StatusString -eq “UpToDate”} = Everything Business, even tho only one has that status.

  10. uday says:

    Get-ODStatus

    is not giving any output.
    Not even,

    Get-ODStatus -Type Business

  11. Peter says:

    Hi Rodney, please help. I am not getting any output unless using -ByPath, like Roberto. Also then I get the StatusString value only. What do I need to change?

    PS C:\Users\schaefpe> import-module -name C:\Users\schaefpe\Downloads\OneDriveLib.dll -verbose
    VERBOSE: Loading module from path ‘C:\Users\schaefpe\Downloads\OneDriveLib.dll’.
    VERBOSE: Importing cmdlet ‘Get-ODStatus’.
    PS C:\Users\schaefpe> Get-ODStatus
    PS C:\Users\schaefpe> Get-ODStatus -Type Business
    PS C:\Users\schaefpe> Get-ODStatus -ByPath “C:\Users\schaefpe\OneDrive – MyCorp”
    UpToDate
    PS C:\Users\schaefpe>

    1. Hi Peter,

      I can think of two things: a) You may have not unblocked the DLL after you downloaded from the Internet; b) There is something wrong with your configuration. If you can do the following I may be able to help you.

      1. Make sure you run PowerShell in regular privileges (elevated privileges does not work with OneDrive and this is by design)

      2. See if the OneDrive folder(s) are shown when you run this command in PowerShell:

      ls -s HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager\

      1. Guru says:

        Hi Rodney,
        i am getting not getting any output by running Get-ODStatus this comandlet . please help me .and i have have unblocked the dll file and not running powershell in elevated mode.
        if i pass the -bypath ‘***’ then i am getting output .and i am not getting what exactly problem is? please help me to get all measures

        1. I have a debug and trace version here: https://github.com/rodneyviana/ODSyncService/tree/master/DebugAndTraces
          It may help you identify the issue. Only use this version for troubleshooting as it adds overhead

  12. jacek says:

    When i do import i get following

    PS C:\ODTool> Import-Module OneDriveLib.dll
    Import-Module : The specified module ‘OneDriveLib.dll’ was not loaded because no valid module file was found in any
    module directory.
    At line:1 char:1
    + Import-Module OneDriveLib.dll
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (OneDriveLib.dll:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

    1. Navigate in Windows Explorer where OneDriveLib.dll is located, right-click and select Unblock and click Ok.

  13. Jari says:

    Fantastic! I am running a script by GPO in the user context to pick up the status. It works fine when run manually but by GPO status is always “Not Installed”. I have tried with Start-Sleep in the script. Any idea what I am missing or if it is possible at all?

    Import-Module c:\it\OneDriveLib.dll
    $UserP= $env:UserProfile
    $ODStatus = Get-ODStatus -ByPath “$userp\OneDrive – Company”

    1. Jari,

      Due to the design of OneDrive you have to run as interactive and in non-elevated administrator privileges. To test if you are running your script in elevated privileges:

      $IsAdmin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match “S-1-5-32-544”)

      Test if you are in interactive mode:
      $IsInteractive = [Environment]::UserInteractive

      These is the situation where the script can run:

      if(-not $IsAdmin -and $IsInteractive)
      {
      Get-ODStatus
      } else
      {
      Write-Host “You need to run in interactive mode and non-admin mode”
      Write-Host “Now, you are running as – Admin Mode = $($IsAdmin) / Interactive: $($IsInteractive)”
      }

  14. Et says:

    When executed remotely (which I guess would be the most interesting case) it always returns NotInstalled. Es:

    $file = “oneDriveLib.dll”
    $session = New-PSSession -ComputerName $computerName
    Copy-Item -Path $file -ToSession $session -Destination ‘C:\Windows\System32\oneDriveLib.dll’

    Invoke-Command -Session $session -ScriptBlock {
    Import-Module ‘C:\Windows\System32\oneDriveLib.dll’
    Get-ODStatus –Type Business
    }

    StatusString : NotInstalled
    [.]

    The same command, executed locally, returns:

    StatusString : UpToDate
    [..]

    Is that normal ?

    1. This is by design of OneDrive. It only works in interactive mode. Many people have this challenge and the best way to resolve this is to schedule a new task to run a PowerShell script and update your monitoring system. Make sure that ‘Run with highest privilege’ is DISABLED as OneDrive also requires this.

  15. S. Rosa says:

    When i call Get-ODStatus my screen blinks twice? Someone have the same issue?

  16. Nilson says:

    When importing the Powershell module I get an error:

    Import-Module: The specified module ‘OneDriveLib.dll’ was not loaded because no sound was
    in any module directory.

    1. Unblock the DLL as specified in previous conversations

  17. Kang Du says:

    Hi Rodney,

    Thanks for this great tool.
    Is there anyway it can check status when OneDrive is running as service using a service account?
    We managed to run OneDrive using local admin account, but This cmdlet doesn’t seem to work.
    Is it because that interactive thing?

    1. Hi Kang,

      This is by design. You can only access status for your account. Also you CANNOT run it in elevated privileges.

  18. Kang Du NZ says:

    Hi Rodney, thanks for this great tool.
    Is it capable to detect OneDrive status when OneDrive runs as a service ?
    We managed to use task scheduler to run OneDrive using a local admin account as a service. When running this comlet we gets NotInstalled. Is it because of the interactive thing?

    1. That is correct. The best way to resolve your problem is to run the PowerShell as a Windows Task Scheduler’s task. Choose to run when user is logged on and DO NOT enable Run with highest privileges

      1. Kang Du NZ says:

        Thanks Rodney for the reply. Then OneDrive is not suitable for our task – a backup agent that runs silently and reports status.
        Need to find third party client for that task.

  19. Colin says:

    Hi Rodney,

    I have two problems with this tool.
    1. When i run it on my machine some document libraries show up as ShareSync and some show up as NotInstalled. They are all configured similarly and are definitely installed.
    2. When i run the script my screen blinks twice.

    Could you help with that?

    1. 1. You cannot run the cmdLet in elevated mode nor in non-interactive mode. The status is only related to the logged user. Read the previous comments to download the debug version of the cmdLet to see what the problems are.
      2. You may be running this as a Windows task and PowerShell shows a window which may be what you are taking for flicking screen.

      1. Ed says:

        Hello Rodney,
        I read all post…no admin right to check OneDrive status, unblock lib…
        I run this :
        Unblock-File -Path “C:\temp\onedrivelib.dll”
        import-module “C:\temp\onedrivelib.dll”
        Get-ODStatus -ByPath $env:onedrive

        result : NotInstalled….
        My businessfolder had number 2….

        is it possible a problem ?
        I also have SharePoint sync….: status : SharedSync.

        i download your debug lib…but where are the log please ?

        Thank you

        1. The log is in %temp%. Choose run, type %temp% and enter. The temp folder should open. Sort by date descending.

  20. Ed says:

    Hello Rodney,
    Thank you. I read all posts : run PowerShell with no admin right, current user OneDrive is running on my win 10…i launch :
    Unblock-File -Path “C:\temp\onedrivelib.dll”
    import-module “C:\temp\onedrivelib.dll”
    Get-ODStatus -ByPath $env:onedrive

    The result is that my business folder number is : Business2….not installed…
    if i use : -Type Business : idem…for my business OneDrive folder : Notinstalled.

    I get your onedrivelib for debug…where are put log please ?

    Thank you very much.

    PS : does with this lib, i can pause syncing ?

Skip to main content