$computer = 'computername';
$users = gwmi win32_LogonSession -Computer $computer -Filter 'LogonType=2 or LogonType=10' | %{
gwmi -ComputerName $computer -Query "Associators of {Win32_LogonSession.LogonId=$($_.LogonId)} Where AssocClass=Win32_LoggedOnUser Role=Dependent" | select -Expand Name
};
$anzahl_user = $users.count;
gives old information, namely user is gone, but according to powershell he is still there. It desturbs the observation of the number of real users in system. Does someone know the reason(s) for such wrong feedback from powershell and which command (which correcton) could give me constantly correct amount of users in system?
I only could control the users via server manager remote desctop Dinste (german name). I expect to get explanation of internal mechanisms, why the command gives me wrong result as well as reccomendation how to correct the prolem. I suppose that some procecces correlated with user are still in process therefore powershell considers user as present, whereas server manager already detected him as absent.
NinaGr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
$UserProfiles = Get-WmiObject -Query "SELECT * FROM Win32_UserProfile WHERE Special != TRUE AND Loaded = TRUE"
foreach ($Profile in $UserProfiles)
{
$UserID = $Profile.LocalPath.Split('') | Select-Object -Last 1
$LoginTable = [ordered]@{'LoginID'=$UserID}
$LoginID = New-Object -TypeName PSObject -Property $LoginTable
Write-Output -InputObject $LoginID
}