I'm trying to use the output of Get-LoggedOnUser.ps1 (which outputs a PSCustomObject) to filter a list of usernames.
Goal: I want to remove from my list any currently logged on users. However, I cannot figure what I'm doing isn't working, even debugging in the ISE. You can see I've even tried to make the object's field names match eachother.
$currentlyLoggedInUsernames = .\Get-LoggedOnUser.ps1
$currentlyLoggedInUsernames = .\Get-LoggedOnUser.ps1 | Select-Object UserName, LogonTime | sort UserName, LogonTime
$currentlyLoggedInUsers = $currentlyLoggedInUsernames | Select-Object UserName | Select-Object @{Name = "Name"; Expression = {$_.UserName}}
$useraccounts = Get-ChildItem -path \\$env:COMPUTERNAME\c$\users\ -Exclude 'public', 'Administrator' | Where-Object Name -notcontains $env:USERNAME
### Trouble below ###
$useraccounts = $useraccounts | Where-Object Name -NotContains $currentlyLoggedInUsers #BUT OTHER CURRENTLY LOGGED IN USERS REMAIN AFTER THIS LINE IS RUN.
$useraccounts #Why doesn't the above line actually remove the other logged in users from the list?