I've made some changes to your powershell code for global usage to save the files in the same directory under webp.
md "$directory/webp"
cd "$directory/webp"
Get-ChildItem $Directory | ForEach-Object {
cwebp.exe -q $compressionFactor -mt -m $compmethod $.fullname -o "$($.basename).webp"
}
$PSScriptRoot
implement it better if you can and repost :)