Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $SQLServer = "databaseserver" #use Server\Instance for named SQL instances!
- $SQLDBName = "databasename"
- $SqlQuery =
- "SELECT [UserName]
- ,InteractiveDesktop = DATEDIFF(Second, [BrokeringDate],[InteractiveEndDate])
- ,GpoDuration = DATEDIFF(Second, [GpoStartDate], [GpoEndDate])
- ,LogonDuration = DATEDIFF(Second, [LogOnStartDate], [LogOnEndDate])
- ,[BrokeringDuration]
- ,[AuthenticationDuration]
- , FORMAT([BrokeringDate] , 'dd-MM-yyyy') AS EasyDate
- , FORMAT([BrokeringDate] , 'HH') AS EasyHour
- ,SUBSTRING([Name],18,4) AS VLAN
- FROM [MonitorData].[Connection]
- LEFT JOIN [MonitorData].[Session]
- ON ([MonitorData].[Connection].[SessionKey] = [MonitorData].[Session].[SessionKey] )
- LEFT JOIN [MonitorData].[Machine]
- ON ([MonitorData].[Session].[MachineId] = [MonitorData].[Machine].[Id])
- LEFT JOIN [MonitorData].[User]
- ON ([MonitorData].[Session].[UserId] = [MonitorData].[User].[Id])
- WHERE [IsReconnect] = 0
- AND [ConnectedViaIPAddress] Not Like '145.121.57.10%'
- AND [BrokeringDate] IS NOT Null
- AND [InteractiveEndDate] IS NOT Null
- AND [UserName] like 'h.oost'
- ORDER BY [UserName], [BrokeringDate], [InterActiveDesktop]
- "
- $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
- $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"
- $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
- $SqlCmd.CommandText = $SqlQuery
- $SqlCmd.Connection = $SqlConnection
- $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
- $SqlAdapter.SelectCommand = $SqlCmd
- $DataSet = New-Object System.Data.DataSet
- [void]$SqlAdapter.Fill($DataSet)
- $SqlConnection.Close()
- #clear
- $DataSet.Tables[0] | ft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement