PowerShell - Cross-Platform PowerShell
You want to write a PowerShell script on Linux that lists all running processes and filters only those owned by the current user. Which approach is correct?
$env:USER to get the current user's name.Where-Object { $_.UserName -eq $env:USER } correctly compares the process owner to the current user.ps -u $USER | pwsh mixes Linux command with PowerShell incorrectly. Get-Process | Where-Object { $_.UserName -eq (whoami) } uses command output that may not match precisely. Get-Process | Where-Object { $_.UserName -eq $env:USERNAME } uses $env:USERNAME which is typically not set on Linux.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions