Created
July 28, 2016 10:00
-
-
Save ringe/b0422bc9fac11a42101f7623db10d8ae to your computer and use it in GitHub Desktop.
Maximum users of an application, limit license usage on Windows Terminal Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# name of procsess we are tracking | |
$limited_process = "notepad.exe" | |
# limit of instances we allow | |
$user_limit = 3 | |
# Limit reached message and title | |
$message = "Too many users! They are:" | |
$title = "No more notepad" | |
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
$msgbox = [System.Windows.Forms.MessageBox] | |
$processes = (Get-WmiObject win32_process -Filter "name='$($limited_process)'") | |
$users = Foreach ($proc in $processes) { $proc.getowner().User } | |
$names = ($users -join ', ').ToUpper() | |
if ($users.count -eq $user_limit) { | |
$msgbox::Show("$($message) $($names)", $title) | |
} else { | |
start $limited_process | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment