Optimizing the Tridion search collection from powershell
We recently had a case of poor search performance on the Tridion content manager. It turned out that you're supposed to optimize the search collection from time to time. We have scripts that look after repetitive maintenance tasks, but this one had been missed. Search performance had probably degraded slowly over time, but we hadn't noticed until we'd tried to run Sync-TcmSearchIndex. The sync operation pushes everything onto the queue to be re-indexed, so we noticed that the very large amount of items in the queue wasn't getting smaller as fast as we'd expected.
Once you know what to look for, the documented advice from SDL is easy enough to find. It's as simple a task as "accessing a URL". Well obviously, we don't want to be poking around with a browser every time this has to happen, so it's a job for Powershell!
Here's how I got it to work on my research system
$pw = ConvertTo-SecureString -AsPlainText -Force "Tridion1"
$credential = New-Object System.Management.Automation.PSCredential("tridionsys", $pw)
Invoke-WebRequest -Uri http://sdlweb:8983/tridion/update?optimize=true -Credential $credential
As you can see, my password security is not a huge concern on this system as it only runs in an environment that's private to me. This means I can get away with a script that doesn't do much to secure the password. If you want to create a script that runs unattended and uses a properly safeguarded password, you'll have to do more juggling with ConvertTo-SecureString and its friends, as described in various blogs, such as this one.