I've been having trouble with my video library where many of my TV shows and movies have incorrect or odd titles that I'd like to fix. I tried writing a PowerShell script to automatically change the titles by walking through the directory and parsing the show, episode, and title. For example, one of the titles in my library looks like this: "The Lieutenant - S01E11 - Fall From A White Horse.x265.384p.mkv". Using command prompt, I can manually change the title with MKVToolNix, but when I run my script, it gives me an error related to the path of MKVToolNix. The specific error says, '''C:Program' is not recognized as an internal or external command, operable program or batch file.'' I really appreciate any help on fixing this issue!
3 Answers
If scripting seems like a hassle, consider using tools like Sonarr or Radarr. They can automatically match titles in your library and handle renaming, which could save you a lot of time and effort!
It looks like one issue might be how you're calling the command in your script. Instead of wrapping it in CMD and needing to escape everything, try calling it directly from PowerShell like this: & $mkvpropeditPath -quiet $file.FullName --edit info --set "title=$newTitle". If you have dynamic arguments, consider using an array with splatting:
$MKVArgs = @(
'-quiet'
$file.FullName
'--edit'
'info'
'--set'
"title=$newTitle"
)
& $mkvpropeditPath @MKVArgs. This way, you don’t need escape characters for the arguments.
Great advice! I’ll definitely give that a try.
You know, I don’t really get why you're going through all this trouble. Plex actually has a built-in feature to refresh all metadata. Have you tried that? I've seen it work perfectly with similar file names, so it might save you from all this hassle.

Your suggestion worked! I'm still getting some odd error log messages, but the titles are being updated correctly now. Here's my updated function with your changes included.