How do i exclude OneDrive subfolders from my file explorer searches

Fuglem, Mark 5 Reputation points
2025-06-16T19:07:49.04+00:00

How do i exclude OneDrive subfolders from my file explorer searches

Windows for business | Windows Client for IT Pros | User experience | Other
{count} vote

3 answers

Sort by: Most helpful
  1. S.Sengupta 24,476 Reputation points MVP
    2025-06-17T02:47:19.37+00:00

    Open Control Panel > opt Large Icons > Indexing Options > Click Modify, then Show all locations > Locate your OneDrive directory and deselect the subfolders you want to exclude > Apply/ok

    1 person found this answer helpful.
    0 comments No comments

  2. Lily-T 240 Reputation points Microsoft External Staff Moderator
    2025-06-17T03:16:15.9733333+00:00

    Dear @Fuglem, Mark 

    Thank you for reaching out Q&A Forum! 

    We understand that you require a guide on how to exclude OneDrive subfolders from your File Explorer searches. 

    Based on our testing environment, please try the following steps: 

    1. Click Window Logo (Start Button) > Go to Settings > Select Privacy & Security.  
    2. Scroll down and select Searching Windows. 

    User's image

    1. Select Advanced indexing options.
    2. The Indexing Options window will open > choose Modify button > Go to your OneDrive folders and untick the subfolders that you want to exclude > click OK and then Close.  

    User's image

    1. The options you exclude will be displayed as below. 

    User's image

     Please visit the link for your reference: Search indexing in Windows - Microsoft Support

    If you have any questions, please feel free to contact us at your convenience.  

    Understanding your use case in more detail will help us recommend the most efficient and compatible solution.  


     If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".    

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

    1 person found this answer helpful.

  3. Fuglem, Mark 5 Reputation points
    2025-06-23T12:34:25.2733333+00:00

    Because I don't have admin priviledges and for other reasons, I finally went with a power shell script (a simplified version follows). This works very well and is very fast. Thanks.

    File C:\Folder1\SearchPDFsWithTwoAuthors.ps1

    Find all pdf's with Author1 and Author2 and write to a text file

    Run the following in Power Shell

    cd ‘C:\Folder1\’

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

    .\SearchTwoAuthorsPDFs.ps1

    $rootDir = "C:\Folder1"

    $outputFile = "C:\Folder1\SearchResults.txt"

    $fileExtension = "*.pdf"

    $keyword1 = "Author1"

    $keyword2 = "Author2"

    $writer = [System.IO.StreamWriter]::new($outputFile, $false, [System.Text.Encoding]::UTF8)

    Directories to skip (any subfolder of these is also skipped)

    $dirsToSkip = @(

    "C:\Folder1\SubFolder1",
    
    "C:\Folder1\OneDrive"
    

    )

    Normalize skip paths (lowercase + no trailing backslash)

    $dirsToSkipNormalized = $dirsToSkip | ForEach-Object { ($_ -replace '\+$', '').ToLower() }

    Get directories recursively, suppress errors

    $directories = Get-ChildItem -Path $rootDir -Directory -Recurse -ErrorAction SilentlyContinue | Where-Object {

    $dirPath = $_.FullName.ToLower()
    
    -not ($dirsToSkipNormalized | Where-Object { $dirPath.StartsWith($_) })
    

    }

    foreach ($dir in $directories) {

    # Only search files in the current directory
    
    $results = Get-ChildItem -Path $dir.FullName -File -Filter $fileExtension -ErrorAction SilentlyContinue |
    
        Where-Object {
    
            $_.Name -like "*$keyword1*" -and $_.Name -like "*$keyword2*"
    
        }
    
    foreach ($result in $results) {
    
        $message = "$($result.Name) in $($result.DirectoryName)"
    
        Write-Host $message -ForegroundColor Green
    
        $writer.WriteLine($message)
    
    }
    

    }

    $writer.Close()


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.