Skip to content

Instantly share code, notes, and snippets.

@junecastillote
Created August 5, 2021 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junecastillote/a2f7fd732ccc38f05cbc9e5d761d5594 to your computer and use it in GitHub Desktop.
Save junecastillote/a2f7fd732ccc38f05cbc9e5d761d5594 to your computer and use it in GitHub Desktop.
Function to Parse Query User / Session
# Function to get the Sessions
Function Get-LoggedOnSessions {
param(
$Server = "localhost"
)
query session /server:$Server |
ForEach-Object {
$_.Trim() -replace '\s{2,}',','
} | ConvertFrom-Csv
}
# Function to get the Users
Function Get-LoggedOnUsers {
param(
$Server = "localhost"
)
query user /server:$Server |
ForEach-Object {
$_.Trim() -replace '\s{2,}',','
} | ConvertFrom-Csv
}
@MarcLaf
Copy link

MarcLaf commented May 25, 2023

I had to add a > in the Trim function to remove the indicator of the current user.

$_.Trim(>) -replace '\s{2,}',','

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment