Forum Discussion

namikou1610's avatar
namikou1610
Copper Contributor
Jan 28, 2025

Unlink OneDrive folder in Windows 10

Hello

I have problem with OneDrive. User is not signed in OneDrive but the folder 'C:\Users\%username%\OneDrive - My Org' exist and you can browse all file names and open files which are cached locally.

I have found out that you can clear saved user credentials by deleteing this json file (https://support.microsoft.com/en-us/office/clear-onedrive-cached-credentials-5b7d944e-89ce-4fbd-812c-a1d93645cfd1) but this does not help because the user is not logged in OneDrive.

del /q /f "%userprofile%\AppData\Local\Microsoft\OneDrive\settings\PreSignInSettingsConfig.json"

In this document https://learn.microsoft.com/en-us/sharepoint/troubleshoot/sync/onedrive-local-folder-name-not-updated it's guided to unlink the user account from OneDrive Settings but this cannot be done because user is not logged in OneDrive.  I have also deleted this reg key as suggested in the document but this this did not help.

reg delete "HKEY_CURRENT_USER\Software\Microsoft\OneDrive" /f 2>nul

Only solution so far have been backing up all files, then removing the whole user profile but this is not practical. I would like to unlink the OneDrive by using PowerShell or a batch file.

 

 

 

 

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    To unlink the OneDrive folder in Windows 10 when the user is not signed in, and avoid removing the entire user profile, you can follow these steps using PowerShell or Command Prompt (batch script). This will remove the OneDrive sync relationship and clean up the local files without needing the user to sign in.

     

    Step 1: Stop the OneDrive Process

    First, make sure OneDrive isn’t running:

    Command Prompt (CMD)

    taskkill /f /im OneDrive.exe

     

    Step 2: Use Command Prompt to Unlink OneDrive Folder

    Run the following commands (CMD) as an administrator:

    # Stop OneDrive process
    taskkill /f /im OneDrive.exe
    
    # Uninstall OneDrive (Optional but ensures clean unlink)
    %SystemRoot%\SysWOW64\OneDriveSetup.exe /uninstall
    
    # Remove OneDrive registry keys (unlink account)
    reg delete "HKEY_CURRENT_USER\Software\Microsoft\OneDrive" /f
    reg delete "HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Common\Identity\Identities" /f
    reg delete "HKEY_CURRENT_USER\Software\Microsoft\IdentityCRL" /f
    
    # Clear OneDrive cached credentials
    del /q /f "%userprofile%\AppData\Local\Microsoft\OneDrive\settings\PreSignInSettingsConfig.json"
    
    # Remove leftover OneDrive folders (adjust path as needed)
    rmdir /s /q "%userprofile%\OneDrive - My Org"
    rmdir /s /q "%localappdata%\Microsoft\OneDrive"

    Step 3: Clean Up via PowerShell (Advanced Script)

    If you prefer PowerShell, use this script:

    powershell

    # Stop OneDrive process
    Stop-Process -Name OneDrive -Force -ErrorAction SilentlyContinue
    
    # Unlink OneDrive by removing registry keys
    Remove-Item -Path "HKCU:\Software\Microsoft\OneDrive" -Recurse -Force -ErrorAction SilentlyContinue
    Remove-Item -Path "HKCU:\Software\Microsoft\Office\16.0\Common\Identity\Identities" -Recurse -Force -ErrorAction SilentlyContinue
    Remove-Item -Path "HKCU:\Software\Microsoft\IdentityCRL" -Recurse -Force -ErrorAction SilentlyContinue
    
    # Clear cached credentials
    $preSignInSettings = "$env:USERPROFILE\AppData\Local\Microsoft\OneDrive\settings\PreSignInSettingsConfig.json"
    If (Test-Path $preSignInSettings) { Remove-Item $preSignInSettings -Force }
    
    # Remove OneDrive folders
    $oneDrivePath = "$env:USERPROFILE\OneDrive - My Org"
    If (Test-Path $oneDrivePath) { Remove-Item -Path $oneDrivePath -Recurse -Force }
    
    # Optional: Uninstall OneDrive if needed
    Start-Process "$env:SystemRoot\SysWOW64\OneDriveSetup.exe" -ArgumentList "/uninstall" -Wait

    Step 4: Reboot

    After running the script or commands:

    • Restart the computer to finalize changes.
    • The OneDrive folder should no longer appear linked to the user account.

     

    Important Notes:

    • Backup any important files before deleting folders.
    • Removing registry keys affects OneDrive settings only, not other applications.
    • For domain environments, consider using Group Policy to manage OneDrive settings centrally.

    By following these steps, you can successfully unlink the OneDrive for Business folder in Windows 10 without removing the entire user profile. The text was created with the help of AI.

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

     

    Was the answer useful? Mark as best response and like it!

    This will help all forum participants.

Resources