|
Variable issues within pipeline using wmi Hi,
I have been messing around with trying to create a single line command to
list logged on users to a machine. I think this should be quiet easy but I
am struggling with the way powershell is handling my variable expansion
within the pipeline.
I expect this command to work, however it doesn't seem to expand the
variable correctly.
gwmi -query "Select logonid from Win32_LogonSession where logontype = 2 or
logontype = 10" -computername aupoza510 | foreach {gwmi -computername
aupoza510 -query 'Associators of {Win32_LogonSession.LogonId=$_.logonid}
Where AssocClass=Win32_LoggedOnUser Role=Dependent'}
The following command does work ... seems very strange to me.
gwmi -query "Select logonid from Win32_LogonSession where logontype = 2 or
logontype = 10" -computername aupoza510 | foreach {gwmi -computername
aupoza510 -query "Associators of{$_} Where AssocClass=Win32_LoggedOnUser
Role=Dependent"}
The other thing I have found strange which is not related to powershell is
that the logontype does not seem correct all the time. I ran the command
against the server where I was terminal serviced in (logontype 10) and it
didn't return my logon. I then checked on the server and my logontype was 0
which is meant to be reserved for the system. Any ideas?
Cheers,
Adam. |