This script was made in the spirit of (Linux/Unix) GNU findutils' locate. It is also in PSGallery, simply run Install-Module locate if you're on PowerShell 5+.

While the name of this script is Invoke-Locate, it actually creates two persistent aliases: locate and updatedb. A fresh index is automatically created every 6 hours, and updatedb can be used force a refresh. Indexing takes anywhere from 30 seconds to 15 minutes, depending on the speed of your drives. Performing the actual locate takes about 300 milliseconds. This is made possible by using SQLite as the backend. Invoke-Locate supports both case-sensitive, and case-insensitive searches, and is case-insensitive by default. 

Locate searches are per-user, and the database is stored securely in your home directory. You can search system files and your own home directory, but will not be able to search for filenames in other users' directories. 

Note: This is a work in progress (version 0.x), and I'm currently testing it in various environments. Please let me know if you have any issues. I fixed a few bugs over the weekend. Please download the newest version.

Basic Install

To install with basic features, simply run .\Invoke-Locate -install

Once the install is complete, and the database is populated, perform your locate.

That's it! The database is automatically populated every 6 hours by a Scheduled Task. To perform a manual update, run updatedb.

Basic Examples

locate csv*.ps1
This performs a case-insensitive search for *csv*.ps1
locate -s System.Data
Case-sensitive search which return the path to any file or directory with System.Data in the name.
Forces a database refresh. This generally takes just a few minutes.
locate .iso  -orderby fullname
Displays filenames in alphabetical order.
locate powers_ell.exe
Similar to SQL's "LIKE" syntax, underscores are used to specify "any single character." locate powers?ell.exe also works.

How it works

locate queries a user-specific SQLite database prepared by updatedb (Task Scheduler) and writes file names matching the pattern to standard output, one per line. Since the back-end is SQL, SQL "LIKE" syntax can be used for the search pattern (ie % and _). Asterisks are automatically translated to % for those who are used to searching with * wildcards. So locate SQ*ite, and locate SQ%ite will return the same results.

To see the SQL statement being performed, use -verbose.

All the searches I've performed have taken about 300ms.

In order to ensure locate always returns results, updatedb first writes to a temporary database, then overwrites the live database with the newly populated data.

The following files will be created in $env:LOCALAPPDATA\locate during the install (System.Data.SQLite.dll will not be downloaded if you have SQLite already in your your GAC.)

Advanced Install

To enable SQL query support and collect additional information about each file (short name, size, directory, time created, time modified), simply run .\Invoke-Locate -install -advanced. Because indexes take longer, updatedb will scheduled to run every 24 hours, instead of every 6. In addition, the du alias is created. du displays Disk Usage reports.

Advanced Examples

(Must have installed Invoke-Locate.ps1 with -advanced switch. You can reinstall just by issuing Invoke-Locate.ps1 -install -advanced)

locate .iso -columns name, mb, gb  -where { gb -gt 1 } -orderby size
Searches for iso files larger than 1 gigabyte and orders the results by size. Returns only specified columns. Note that the -columns and -orderby columns are auto-populated so you do not have to guess.
locate -sql "select directory from files where fullname like'%chrissy%resume%.docx' and lastmodified > '1/1/2015' order by lastmodified"
Executes the above SQL statement and returns a datatable. When the -sql switch is used, all other switches are ignored.
locate -sql "select count(*), sum(gb) from files where directory like '%$env:HOMEPATH%'"
Returns the total number and size of the files within your home directory
locate -sql "SELECT fullname, gb FROM files ORDER BY size DESC LIMIT 10"
Finds the 10 largest files, ordered by size

This command displays disk usage output for the current directory, including files and directories
du -topdirectories C:\inetpub 
Aggregates disk usage information by directory for C:\inetpub


This script was made in the spirit of (Linux/Unix) GNU findutils' locate. "locate" and "updatedb" aliases are automatically created. 
While the name of this script is Invoke-Locate, it actually creates two persistent aliases: locate and updatedb. A fresh index is automatically created every 6 hours, updatedb can be used force a refresh. Indexing takes anywhere from 30 seconds to 15 minutes, depending on the speed of your drives. Performing the actual locate takes about 300 milliseconds. Invoke-Locate supports both case-sensitive, and case-insensitive searches, and is case-insensitive by default. 
locate queries a user-specific SQLite database prepared by updatedb (Task Scheduler) and writes file names matching the pattern to standard output, one per line. Since the back-end is SQL, SQL "LIKE" syntax can be used for the search pattern (ie % and _). Asterisks are automatically translated to % for people who are used to searching with * wildcards. So locate SQ*ite, and locate SQ%ite will return the same results. 
By default, locate does not check whether files found in database still exist; locate cannot report files created after the most recent update of the relevant database. 
Installing the script using -advanced option additional data collection (fullname, name, directory, size, created, lastmodified), and enables SQL querying. 
.PARAMETER filename 
You actually don't have to specify the -filename parameter. Just locate whatever. 
.PARAMETER install 
Installs script to $env:LOCALAPPDATA\locate, which allows each user to have their own secured locate database. 
    - Sets persistent locate and updatedb user aliases. 
    - Checks for the existence of System.Data.SQLite.dll. If it does not exist, it will be automatically downloaded to $env:LOCALAPPDATA\locate. 
      To skip this step, download System.Data.SQLite and register it to the GAC. 
    - Creates the database in $env:LOCALAPPDATA\locate. 
    - Creates the initial table. 
    - Creates a schedule task named "updatedb cron job for user [username] (PowerShell Invoke-Locate)" that runs every 6 to 24 hours. This step may prompt for a username and password if the account does not have adequate access to create the scheduled task automatically. 
      *Note: even though an elevated SYSTEM account is used for administrator installs, home directories of other users are excluded from index. 
    - Prompts users to specify if mapped drives should be indexed. Take note that mapped drives can be huge. 
    - Prompts user to run updatedb for the first time. 
Install can be run repeatedly with no issues. To uninstall, delete $env:LOCALAPPDATA\locate, the Scheduled Task, and the two aliases within $profile. 
.PARAMETER advanced 
The advanced switch tells locate to index: fullname, name, directory, size, created, lastmodified. Because updatedb will take about 20% longer, Task Scheduler will execute updatedb every 12 hours instead of 6. Installing with the advanced options will allow you to perform advanced queries on the database. 
Similar to findutils locate's "-i" switch for case-insensitive, this switch makes the search sensitive. By default, Windows searches are insensitive, so the default search behavior of this script is case-insensitive. 
This parameter will allow you to perform SQL queries directly to your SQLite database. Default installs only allow "SELECT fullname..." Advanced installs also allow "SELECT fullname, name, directory, size, created, lastmodified..." 
This parameter will allow you to perform a WHERE on the default select. Ignored if you specify -sql. 
.PARAMETER orderby 
This parameter will allow you to perform an ORDER BY by on the default select. Ignored if you specify -sql. 
.PARAMETER Descending 
Adds descending sort order to -orderby. 
.PARAMETER columns 
This parameter will allow you to return specific columns from a dataset by on the default select. Columns names are populated from database. Ignored if you specify -sql. 
Limits returned rows by specified numbers 
When Invoke-Locate.ps1 is installed with the -advanced switch, a Disk Usage (du) alias is installed. This command displays disk usage output for the current directory, including files and directories. 
.PARAMETER topdirectories 
When used in conjunction with -du, -topdirecotries displays a human-readable disk usage report of largest directories. Beware, you'll be tempted to run this command on C:\ or C:\Program Files. I wouldn't. 
.PARAMETER updatedb 
Internal parameter. You don't need to pass -updatedb. Just use the updatedb alias. 
.PARAMETER includemappeddrives 
Internal parameter. Tells updatedb to include mapped drives. 
.PARAMETER locatepath 
Internal parameter. Specifies locate's program directory. 
.PARAMETER userprofile 
Internal parameter. This helps support mulit-user scheduled task updates.  
.PARAMETER homepath 
Internal parameter. This helps support mulit-user scheduled task updates. 
Author  : Chrissy LeMaire  
Requires:     PowerShell Version 3.0 
DateUpdated: 2015-Feb-2 
Version: 0.7.1 
.\Invoke-Locate.ps1 -install 
Copies necessary files, adds aliases, sets up updatedb Scheduled Task to run every 6 hours, prompts user to populate database. 
.\Invoke-Locate.ps1 -install -advanced 
Copies necessary files, adds aliases, sets up updatedb Scheduled Task to run only once a day, and adds additional fields to the database. 
locate powershell.exe 
Case-insensitive search which return the path to any file or directory named powershell.exe     
Forces a database refresh. This generally takes just a few minutes, unless you've specified -advanced during the install. 
locate power*.exe 
Case-insensitive search which return the path to any file or directory that starts with power and has exe after csv in the path. 
locate -s System.Data.SQLite 
Case-sensitive search which return the path to any file or directory named System.Data.SQLite. 
locate powers_ell.exe 
Similar to SQL's "LIKE" syntax, underscores are used to specify "any single character." 
locate .iso -columns name, mb, gb  -where { gb -gt 1 } -orderby size 
Searches for iso files larger than 1 gigabyte and orders the results by size. Returns only specified columns. Note that the -columns and -orderby columns are auto-populated so you do not have to guess. 
When Invoke-Locate.ps1 is installed with the -advanced switch, a Disk Usage (du) alias is installed. This command displays disk usage output for the current directory, including files and directories. 
.EXAMPLE du -topdirectories C:\inetpub 
Aggregates disk usage information by directory for C:\inetpub 
Also confirmed to be working on Windows 10.
5/12/2015: Added error handling for reinstalls, added a note to make it look more like GNU when no parameters are passed.
2/2/2015: Added support for creating Scheduled Tasks as a regular user. Updated potential for scheduled task to leave running bg processes.
2/2/2015: Fixed issues with apostrophes and spaces in usernames.
2/2/2015: Added Disk Usage support for advanced installs. Cleaned up some code.
1/29/2015: Escaped some SQL.
1/29/2015: Fixed escape bug for users with spaces in their usernames or home directories for users with spaces. Users with apostrophies still impacted.
1/28/2015: Added SQL support. 
1/26/2015: Added Unblock-File for DLL, which stopped the DLL from being on systems with max UAC.
1/26/2015: Updated SQLite DLL. Now requires .NET 3.5+ instead of 4+
1/26/2015: I was unaware that reloading advanced profiles can cause errors. Updated the logic to not force a profile update.
1/25/2015: Updated updatedb to write to a temporary database first, then replace the live database with the database of newly populated data.
1/24/2015: Initial upload.