PowerShell GUI Application: Which PC is User logged into..?
This PowerShell GUI application allows you to search for a user's login status on various PCs within your Active Directory domain. The script utilizes the System.Windows.Forms namespace and runspace pools to execute multiple threads concurrently.
Prerequisites
The Script
The script generates a Windows Forms GUI with several controls, including:
How It Works
Search Process
The script uses a runspace pool with multiple threads to concurrently search for the specified user's login status on various PCs within your Active Directory domain. Each thread executes the following steps:
Scriptblocks and Runspace Pools
The script uses PowerShell's built-in support for runspaces and scriptblocks to execute multiple threads concurrently. This allows the script to efficiently search for the specified user's login status on multiple PCs simultaneously.
Key Code Snippets
$Scriptblock = {
#Get explorer.exe processes without credentials parameter if the query is executed on the localhost
$proc = gwmi win32_process -ErrorAction SilentlyContinue -computer $Computer -Filter "Name = 'explorer.exe'"
#If $proc is empty return msg else search collection of processes for username
if ([string]::IsNullOrEmpty($proc)) {
$results.Items.add("$user not found on $Computer!")
} else {
$progress++
ForEach ($p in $proc) {
$temp = ($p.GetOwner()).User
if ($temp -eq $User) {
$Results.ForeColor = 'green'
$results.items.add("$User found logged on $Computer")
$f = 1
}
}
}
}
Usage Examples
To use this script, simply run the `GenerateForm` function and interact with the generated GUI. Enter the user's username and PC filter (if desired), then click the "Search" button to start the search process.
Conclusion
This PowerShell GUI application provides an efficient way to search for a user's login status on various PCs within your Active Directory domain. The script utilizes runspaces and scriptblocks to execute multiple threads concurrently, making it suitable for large-scale searches or high-traffic environments.