Skip to content

Instantly share code, notes, and snippets.

@nanoDBA
Created February 6, 2023 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanoDBA/2b7ae077767eb3d5ff5115faadf1f839 to your computer and use it in GitHub Desktop.
Save nanoDBA/2b7ae077767eb3d5ff5115faadf1f839 to your computer and use it in GitHub Desktop.
Shows users currently using process Ssms.exe in a loop executing every 55 minutes
do {
$ssms = Get-WmiObject -Class Win32_Process -Filter "name = 'Ssms.exe'"
<# Timer/time bomb stub #> $now = Get-Date
$timespan = New-TimeSpan -Start $now -End (Get-Date).AddMinutes(55) # '20:25') #'2077-10-09 19:30'
Write-Host -ForegroundColor magenta "SSMS active user count: $(($ssms.GetOwner()).User.count)"
Write-Host -ForegroundColor magenta "SSMS active users: $(($ssms.GetOwner()).User)"
Write-Host -ForegroundColor magenta "Sleeping until $((Get-date).AddSeconds($timespan.TotalSeconds)) ..."
Start-Sleep -Seconds $timespan.TotalSeconds
}
while ( ($ssms.GetOwner()).User.count -GT 0 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment