Replace -eq
with -match
-eq
is for strict equality-match
is for patterns. If you asked for a prefix then add a Circumflex Accent at start:$_.Name -match "^$SearchPrefix"
As a side note, your two last foreach are useless and will block ouput AFAICS.
Get-Service | Where-Object { $_.Status -eq "Stopped" } | Where-Object { $_.Name -match $SearchPrefix}
will output something like
Status Name DisplayName
------ ---- -----------
Stopped WinHttpAutoProx... Service de découverte automatique d...
Stopped WinRM Gestion à distance de Windows (Gest...
If you want only the two first columns, then add
| Format-Table -auto -property Status, Name