Monday 4 December 2017

Powershell - Wait for process from current user

After much searching online I couldn't find a way to do this without WMI and a bunch of extra work... So I figured this out. Tested and working in Windows 10 at least.

$user = "$env:USERDOMAIN\$env:USERNAME"
$proc = Get-Process -Name notepad -IncludeUserName | where {$_.UserName -eq $user}
Wait-Process -InputObject $proc


That will look for all instances of notepad running under the current user, and wait for all of them to terminate before continuing.

Super useful when waiting for something like msiexec

No comments:

Post a Comment

Deploy Chocolatey packages with Microsoft Intune

 Deploying Chocolatey packages using Intune Let me start by saying this is currently working with Chocolatey version 2.2.2 in August of 2023...