Skip to content

Instantly share code, notes, and snippets.

@nickadam
Created April 5, 2023 13:38
Show Gist options
  • Save nickadam/d60eee6d1795f537501fd10f071eaf0d to your computer and use it in GitHub Desktop.
Save nickadam/d60eee6d1795f537501fd10f071eaf0d to your computer and use it in GitHub Desktop.
Get session data from Always On VPN
# 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