I've written a script which does a benchmark on the time taken to run any command that I input, such as ping google.com -n 1
and I'm having trouble with the output.
When I run the code in an interactive shell, it is fine, but when I run it as a powershell .ps1
script, it puts out chinese characters like this:
〱䘠扥ㄠ㨰㈵瀉湩潧杯敬挮浯ⴠऱ㌲⸹ㄷ㔳獭
That is the "result" from ping google.com -n 1
Needless to say, I'm a little confused as to why it is doing this...
Any ideas?
This is my code:
$command = Read-Host "Enter command"
"DateTime`tCommand`tTime Taken" | Out-file "$($command -replace '[^A-Za-z]','').csv"
While (1) {
$time = date -f "dd MMM HH:mm"
$cmdtime = [string](
Measure-Command {iex $command}
).TotalMilliseconds + "ms"
"$($time)`t$($command)`t$($cmdtime)" | Out-File "$($command -replace '[^A-Za-z]','').csv" -a
Sleep 60;
}