How to split a string by spaces in a Windows batch file? didn't work for me.
I issue a Windows command to list the session ID of the logged in user, like this
PS C:\> $id = (quser /server:'ServerName' | Where-Object { $_ -match 'User' })
PS C:\> echo $id
User console 4 Active none 6/13/1023 9:00 AM
How can I get the session id "4" from the output? I tried
PS C:\> $id = (quser /server:'ServerName' | Where-Object { $_ -match 'User' }).split(' ')[2]
but $id
is just a blank string.
TIA