简体   繁体   中英

Powershell Control Windows Search through command line

I am trying to write a powershell script that will disable indexing on some drives but keep it activated on some others (ex: C:).

Has anyone done it before ?

Thanks

try this, (not tested):

function Disable-Indexing{
    Param($Drive)
    $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
    }
}

use:

disable-indexing "c:"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM