Created
April 5, 2023 13:38
-
-
Save nickadam/d60eee6d1795f537501fd10f071eaf0d to your computer and use it in GitHub Desktop.
Get session data from Always On VPN
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
# Connect to windows internal database, remote access account database, and get relevant information for all active sessions | |
$ConnectionString = 'server=\\.\pipe\MICROSOFT##WID\tsql\query;database=RaAcctDb;trusted_connection=true;' | |
$SQLConnection= New-Object System.Data.SQLClient.SQLConnection($ConnectionString) | |
$SQLConnection.Open() | |
$SQLCommand = $SQLConnection.CreateCommand() | |
$SQLCommand.CommandText = 'SELECT * FROM dbo.ConnectionTable JOIN dbo.SessionTable ON dbo.ConnectionTable.ConnectionId = dbo.SessionTable.ConnectionId WHERE SessionState = 1' | |
$SqlDataReader = $SQLCommand.ExecuteReader() | |
$SQLDataResult = New-Object System.Data.DataTable | |
$SQLDataResult.Load($SqlDataReader) | |
$SQLConnection.Close() | |
$SQLDataResult |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment