Created
August 5, 2021 15:53
-
-
Save junecastillote/a2f7fd732ccc38f05cbc9e5d761d5594 to your computer and use it in GitHub Desktop.
Function to Parse Query User / Session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to add a > in the Trim function to remove the indicator of the current user.
$_.Trim(>) -replace '\s{2,}',','