Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Output of ###
- Get-WmiObject -class "Win32_TSGatewayConnection" -namespace "root\cimv2\TerminalServices" -ComputerName mwRDPGate-M1 -Authentication 6
- ###
- ConnectedResource : ts-p1
- ConnectedTime : 20160520171915.190000-000
- ConnectionDuration : 00000000023717.000000:000
- #########
- $server = "mwSQL-M1"
- $database = "User_Monitor"
- $table = "RDP_Session_Logs"
- $lastIdle = $idleTime
- $temp = 0
- $session = Get-WmiObject -class "Win32_TSGatewayConnection" -namespace "root\cimv2\TerminalServices" -ComputerName mwRDPGate-M1 -Authentication 6
- foreach($item in $session) {
- $cSession = $session[$temp]
- $userName = $cSession.UserName
- $hostName = $cSession.ConnectedResource
- $startTime = ($cSession.ConvertToDateTime($cSession.ConnectedTime)).DateTime
- $totalTime = ($cSession.ConvertToDateTime($cSession.ConnectionDuration)).DateTime
- $idleTime = $cSession.IdleTime
- $guid = [System.GUID]::NewGuid().ToString()
- #Invoke-Sqlcmd -database $database -serverinstance $server -query "insert into $table (Session_ID,Username,Hostname,Session_Start,Session_Time,Idle_Time) VALUES ('$temp','$userName','$hostName','$startTime','$totalTime','$idleTime')"
- write-host $userName $temp $startTime
- $temp = $temp+1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement