mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Added provider for logged in Windows users
This commit is contained in:
parent
972bc904b2
commit
37485d2cd9
1 changed files with 43 additions and 0 deletions
43
lib/provider/users/Get-IcingaLoggedOnUsers.psm1
Normal file
43
lib/provider/users/Get-IcingaLoggedOnUsers.psm1
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
function Get-IcingaLoggedOnUsers()
|
||||
{
|
||||
param(
|
||||
[array]$UserFilter = @()
|
||||
);
|
||||
|
||||
[hashtable]$UserList = @{};
|
||||
[int]$UserCount = 0;
|
||||
$UserList.Add('users', @{ });
|
||||
|
||||
$Users = Get-CIMInstance Win32_LoggedOnUser | Select-Object Antecedent, Dependent;
|
||||
|
||||
foreach ($user in $Users) {
|
||||
[string]$username = $user.Antecedent.Name;
|
||||
|
||||
if ($UserFilter.Count -ne 0) {
|
||||
if (-Not $UserFilter.Contains($username)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$UserCount += 1;
|
||||
|
||||
if ($UserList.users.ContainsKey($username) -eq $FALSE) {
|
||||
$UserList.users.Add(
|
||||
$username,
|
||||
@{
|
||||
'domains' = @($user.Antecedent.Domain);
|
||||
'logonid' = @($user.Dependent.LogonId);
|
||||
'count' = 1;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$UserList.users[$username].domains += $user.Antecedent.Domain;
|
||||
$UserList.users[$username].logonid += $user.Dependent.LogonId;
|
||||
$UserList.users[$username].count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
$UserList.Add('count', $UserCount);
|
||||
|
||||
return $UserList;
|
||||
}
|
||||
Loading…
Reference in a new issue