Prerequisites
Steps to reproduce
After stopping processes on another user with Stop-Process and then waiting for them with Wait-Process, oftentimes blanks fields on the process objects, notably ProcessName. This happens unreliably and seems to happen more if it's done in a function and then the processes are returned to be stored in a variable to then be displayed. This doesn't seem to happen when calling processes WaitForExit method instead of Wait-Process.
Tested on Powershell v7.7.0-preview.3, v7.6.5 and notably on Windows Powershell v5.1.26100.9168 where it seems to almost always happen with most fields blanked/zeroed.
To reproduce run this
$ErrorActionPreference="stop"
$user=New-LocalUser -NoPassword test_waitprocess_bug
try{
$pass=ConvertTo-SecureString -AsPlainText -Force "wowverysecure"
Set-LocalUser $user -Password $pass
function start_procs{
1..10 | ForEach-Object {
[System.Diagnostics.Process]::Start((New-Object System.Diagnostics.ProcessStartInfo winver -Property @{
UserName=$user;
Password=$pass;
UseShellExecute=$false;
WorkingDirectory="C:\"
}))
} | Out-Null
}
function test{
param(
[switch]$expected_behavior
)
$procs=Get-Process -IncludeUserName | Where-Object UserName -EQ "${env:COMPUTERNAME}\$user"
Stop-Process -Force $procs
if($expected_behavior){
$procs | ForEach-Object {$_.WaitForExit()}
}else{
$procs | Wait-Process
}
$procs
}
start_procs
$procs=test
Write-Output "Actual bad behavior:"
Write-Output $procs
Write-Output ""
start_procs
$procs=test -expected_behavior
Write-Output "Expected good behavior:"
Write-Output $procs
}finally{
Remove-LocalUser $user
}
Expected behavior
WS(M) CPU(s) Id UserName ProcessName
----- ------ -- -------- -----------
0.00 0.06 2160 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.16 2360 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.06 3884 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.05 4388 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.08 4460 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.09 4676 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.12 7900 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.11 9536 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.12 11004 DESKTOP-XXXXXXX\test_waitproc… winver
0.00 0.16 11092 DESKTOP-XXXXXXX\test_waitproc… winver
Actual behavior
WS(M) CPU(s) Id UserName ProcessName
----- ------ -- -------- -----------
0.00 0.09 148 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.00 1880 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.05 2500 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.08 5608 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.05 5832 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.12 6992 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.14 7656 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.03 9800 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.03 10708 DESKTOP-XXXXXXX\test_waitproc…
0.00 0.08 11184 DESKTOP-XXXXXXX\test_waitproc…
Error details
Environment data
Name Value
---- -----
PSVersion 7.7.0-preview.3
PSEdition Core
GitCommitId 7.7.0-preview.3
OS Microsoft Windows 10.0.26200
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Prerequisites
Steps to reproduce
After stopping processes on another user with Stop-Process and then waiting for them with Wait-Process, oftentimes blanks fields on the process objects, notably ProcessName. This happens unreliably and seems to happen more if it's done in a function and then the processes are returned to be stored in a variable to then be displayed. This doesn't seem to happen when calling processes WaitForExit method instead of Wait-Process.
Tested on Powershell v7.7.0-preview.3, v7.6.5 and notably on Windows Powershell v5.1.26100.9168 where it seems to almost always happen with most fields blanked/zeroed.
To reproduce run this
Expected behavior
Actual behavior
Error details
Environment data
Visuals
No response