{"id":835,"date":"2018-11-09T12:52:42","date_gmt":"2018-11-09T11:52:42","guid":{"rendered":"http:\/\/www.vatland.no\/?p=835"},"modified":"2018-11-09T12:54:01","modified_gmt":"2018-11-09T11:54:01","slug":"powershell-to-get-directaccess-connection-history","status":"publish","type":"post","link":"https:\/\/www.vatland.no\/index.php\/powershell-to-get-directaccess-connection-history\/","title":{"rendered":"Powershell to get DirectAccess connection history."},"content":{"rendered":"<p>This is a simple powershell to get data from the DirectAccess database. It reguired some serious Bing&#8217;ing (and google) to get the time field. You will have to configure reporting database in DirectAccess config. I used windows internal database.<\/p>\n<div class=\"codecolorer-container powershell default\" style=\"overflow:auto;white-space:nowrap;width:435px;\"><div class=\"powershell codecolorer\"><span class=\"re0\">$server<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\\\\.\\pipe\\MICROSOFT##WID\\tsql\\query&quot;<\/span><br \/>\n<span class=\"re0\">$database<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;RaAcctDb&quot;<\/span><\/div><\/div>\n<div class=\"codecolorer-container powershell default\" style=\"overflow:auto;white-space:nowrap;width:435px;height:300px;\"><div class=\"powershell codecolorer\"><span class=\"co1\">#$table=&quot;connectiontable&quot;<\/span><br \/>\n<span class=\"re0\">$table<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;sessiontable&quot;<\/span><br \/>\n<span class=\"co1\">#$table=&quot;endpointsaccessedtable&quot;<\/span><br \/>\n<span class=\"co1\">#$table=&quot;serverendpointtable&quot;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$cs<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;server=$server;database=$database;Integrated Security=True;&quot;<\/span><br \/>\n<span class=\"re0\">$connection<\/span><span class=\"sy0\">=<\/span><span class=\"kw1\">New-Object<\/span> System.Data.SqlClient.SqlConnection<br \/>\n<span class=\"re0\">$connection<\/span>.ConnectionString<span class=\"sy0\">=<\/span><span class=\"re0\">$cs<\/span><br \/>\n<span class=\"re0\">$connection<\/span>.Open<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<br \/>\n<span class=\"co1\">#$query=&quot;Select * from $table&quot;<\/span><br \/>\n<span class=\"co1\">#$query=&quot;Select * from $database.INFORMATION_SCHEMA.TABLES&quot;<\/span><br \/>\n<span class=\"re0\">$query<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;declare @start bigint=131277336299720000;select dateadd(mi,datediff(mi,getutcdate(),getdate()),([sessionstarttime]\/864000000000.0-109207)) AS DATO,* from sessiontable join connectiontable on sessiontable.connectionid=connectiontable.connectionid where sessionstarttime &amp;amp;gt;=@start&quot;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$command<\/span><span class=\"sy0\">=<\/span><span class=\"re0\">$connection<\/span>.CreateCommand<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"re0\">$command<\/span>.CommandText<span class=\"sy0\">=<\/span><span class=\"re0\">$query<\/span><br \/>\n<span class=\"re0\">$result<\/span><span class=\"sy0\">=<\/span><span class=\"re0\">$command<\/span>.ExecuteReader<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$resulttable<\/span><span class=\"sy0\">=<\/span><span class=\"kw1\">New-Object<\/span> System.Data.DataTable<br \/>\n<span class=\"re0\">$resulttable<\/span>.Load<span class=\"br0\">&#40;<\/span><span class=\"re0\">$result<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"re0\">$resulttable<\/span> <span class=\"sy0\">|<\/span> Out<span class=\"sy0\">-<\/span>GridView<br \/>\n<span class=\"re0\">$connection<\/span>.Close<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><\/div><\/div>\n<div class=\"codecolorer-container powershell default\" style=\"overflow:auto;white-space:nowrap;width:435px;\"><div class=\"powershell codecolorer\">&nbsp;<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This is a simple powershell to get data from the DirectAccess database. It reguired some serious Bing&#8217;ing (and google) to get the time field. You will have to configure reporting database in DirectAccess config. I used windows internal database. $server=&quot;\\\\.\\pipe\\MICROSOFT##WID\\tsql\\query&quot; $database=&quot;RaAcctDb&quot; #$table=&quot;connectiontable&quot; $table=&quot;sessiontable&quot; #$table=&quot;endpointsaccessedtable&quot; #$table=&quot;serverendpointtable&quot; $cs=&quot;server=$server;database=$database;Integrated Security=True;&quot; $connection=New-Object System.Data.SqlClient.SqlConnection $connection.ConnectionString=$cs $connection.Open&#40;&#41; #$query=&quot;Select * from $table&quot; &hellip; <a href=\"https:\/\/www.vatland.no\/index.php\/powershell-to-get-directaccess-connection-history\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Powershell to get DirectAccess connection history.<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[61,59,62],"class_list":["post-835","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-directaccess","tag-powershell","tag-sql"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack-related-posts":[{"id":975,"url":"https:\/\/www.vatland.no\/index.php\/log-tenants-from-office-365-to-local-db\/","url_meta":{"origin":835,"position":0},"title":"Log tenants from office 365 to local Db","author":"Atle","date":"January 3, 2021","format":false,"excerpt":"Hi, I like to keep control of how many licenses our cutomers use versus how many\u00a0 have been purchased. Here is 1st part\u00a0 my PS script to copy the info from csp to the DB. I will start creating a database and table to keep a list of all the\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/www.vatland.no\/index.php\/category\/azure\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":990,"url":"https:\/\/www.vatland.no\/index.php\/get-tenantlistindb-from-previous-post\/","url_meta":{"origin":835,"position":1},"title":"Get-tenantlistindb (from previous post)","author":"Atle","date":"January 8, 2021","format":false,"excerpt":"Now that we have our tenants listed in a database table, listing them is quite easy. Added a switch that allow you to also list deleted\/removed tenants. [cc language=\"powershell\"] function get-tenantlistindb { param( [switch]$all ) $SQLInstance = \"localhost\\SQLExpress\" $SQLDatabase = \"Microsoft365\" $sqlqr = \"select * from [Microsoft365].[dbo].[tenants]\" if (-not $all)\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/www.vatland.no\/index.php\/category\/azure\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1043,"url":"https:\/\/www.vatland.no\/index.php\/list-user-and-license-in-database\/","url_meta":{"origin":835,"position":2},"title":"List users and licenses in Database","author":"Atle","date":"March 26, 2021","format":false,"excerpt":"Now that we have a database containing user, tenant and license it would be nice to have a function\/command to list this. Took me a while to figure it out but thanks to Bing, I prefer Bing before google. I sync my database on a schedule once a day. This\u2026","rel":"","context":"In &quot;CSP&quot;","block_context":{"text":"CSP","link":"https:\/\/www.vatland.no\/index.php\/category\/csp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1010,"url":"https:\/\/www.vatland.no\/index.php\/add-tenant-licenses-from-csp-to-database\/","url_meta":{"origin":835,"position":3},"title":"Add tenant licenses from csp to database.","author":"Atle","date":"January 17, 2021","format":false,"excerpt":"This is a followup from previus post. In this post I will populate the database with what licenses a tenant has aquired. This will add records of what aquired skus and 'usage'. For me this is how many license are bought versus how many are assigned. This does not account\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/www.vatland.no\/index.php\/category\/uncategorized\/azure-uncategorized\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1018,"url":"https:\/\/www.vatland.no\/index.php\/use-get-tenantlicsindb-after-syncing-them-to-our-local-db\/","url_meta":{"origin":835,"position":4},"title":"Use get-tenantlicsindb after syncing them to our local db.","author":"Atle","date":"January 31, 2021","format":false,"excerpt":"Ok, Now that we have syncronized our customers licenes to a local DB, we have this new commandlet to list them. This is a easy one, no advanced tokens setup to connect to Microsoft endpoint, only local database. [cc language=powershell] function get-tenantlics { [CmdletBinding()] param( [int]$lastndays = 1 ) DynamicParam\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/www.vatland.no\/index.php\/category\/uncategorized\/azure-uncategorized\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":367,"url":"https:\/\/www.vatland.no\/index.php\/exchange-server-quarantined-a-mailbox\/","url_meta":{"origin":835,"position":5},"title":"Exchange server quarantined a mailbox.","author":"Atle","date":"November 11, 2014","format":false,"excerpt":"One user tried to run an attachment in a newly received email \u00a0. After this his mailbox became inaccessible. When he tried to access it\u00a0using OWA the familiar message appeared\u00a0: Something went wrong. My first thought was that the database was dismounted, but other mailboxes on the same database still\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"exchange","src":"https:\/\/i0.wp.com\/www.vatland.no\/wp-content\/uploads\/2014\/09\/exchange.jpg?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts\/835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/comments?post=835"}],"version-history":[{"count":4,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts\/835\/revisions"}],"predecessor-version":[{"id":843,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/posts\/835\/revisions\/843"}],"wp:attachment":[{"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/media?parent=835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/categories?post=835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vatland.no\/index.php\/wp-json\/wp\/v2\/tags?post=835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}