IT Knowledge Base

Technical Repository

HowTo: Powershell – Disable Drive Indexing

Create a file named Disable_Disk_Indexing.ps1 and copy and paste the following:

function Disable-Indexing {
    $obj = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter='$Drive'"
    $indexing = $obj.IndexingEnabled
    if("$indexing" -eq $True){
        write-host "Disabling indexing of drive $Drive"
        $obj | Set-WmiInstance -Arguments @{IndexingEnabled=$False} | Out-Null

#Disable Drive Indexing on C:\

Disable-Indexing "C:"

Don’t forget to set the execution policy on the system you are running this script on so that it will run. i.e.

Set-ExecutionPolicy ByPass

Leave a Reply