You can run these lines, one at a time, from Windows Powershell:
Get-ChildItem * | Rename-Item -NewName { $_.Name -replace ' ','_' }
Get-ChildItem * | Rename-Item -NewName { $_.Name -replace '__','_' }
Get-ChildItem * | Rename-Item -NewName { $_.Name -replace '_\.','.' }
This will replace all spaces with underscores (_), remove any two consecutive underscores as well as underscores at the end of the file name.
NOTE: Make sure change directory (CD) into the correct folder before you run these. You don't want to mistakenly run these in a system folder. ?