<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RD Gateway | KC's Blog</title>
	<atom:link href="https://www.kjctech.net/tag/rd-gateway/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kjctech.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2023 18:20:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.kjctech.net/wp-content/uploads/2016/12/cropped-KC-Logo.png?fit=32%2C32&#038;ssl=1</url>
	<title>RD Gateway | KC's Blog</title>
	<link>https://www.kjctech.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">24634607</site>	<item>
		<title>Renewing SSL Certificate on Remote Desktop Gateway Server</title>
		<link>https://www.kjctech.net/renewing-ssl-certificate-on-remote-desktop-gateway-server/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=renewing-ssl-certificate-on-remote-desktop-gateway-server</link>
					<comments>https://www.kjctech.net/renewing-ssl-certificate-on-remote-desktop-gateway-server/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Fri, 10 Aug 2018 22:33:54 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[RD Gateway]]></category>
		<category><![CDATA[SSL]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=4165</guid>

					<description><![CDATA[<p>The wildcard SSL certificate is expiring in a few weeks. It&#8217;s time to get it renewed for both website and the Gateway server for remote access. I renewed the certificate on Namecheap, regenerated the CSR file and got the digitally signed certificate file in a few minutes. Since the digital certificate was generated for the website hosted on Apache, I [&#8230;]</p>
The post <a href="https://www.kjctech.net/renewing-ssl-certificate-on-remote-desktop-gateway-server/">Renewing SSL Certificate on Remote Desktop Gateway Server</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>The wildcard SSL certificate is expiring in a few weeks. It&#8217;s time to get it renewed for both website and the Gateway server for remote access. I renewed the certificate on <a href="https://affiliate.namecheap.com/?affId=120695" target="_blank" rel="noopener">Namecheap</a>, regenerated the CSR file and got the digitally signed certificate file in a few minutes.</p>



<p>Since the digital certificate was generated for the website hosted on Apache, I needed to convert it to PFX/PKCS#12 format for it to work with IIS. There are a couple of online tools that can get the job done flawlessly, such as <a href="https://www.sslshopper.com/ssl-converter.html" target="_blank" rel="noopener">this</a> and <a href="https://decoder.link/converter/" target="_blank" rel="noopener">this</a>. You will need to provide a password to secure the output digital certificate file.</p>



<figure class="wp-block-image"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="640" height="405" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=640%2C405&#038;ssl=1" alt="" class="wp-image-4166" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?w=870&amp;ssl=1 870w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=250%2C158&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=450%2C285&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=768%2C486&amp;ssl=1 768w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=600%2C380&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=700%2C443&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=520%2C329&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=360%2C228&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image.png?resize=100%2C63&amp;ssl=1 100w" sizes="(max-width: 640px) 100vw, 640px" /></figure>



<p>Once I&#8217;ve got the .pfx file, I copied it over to the Gateway server and imported it to the local computer&#8217;s certificate repository. Simply double-click <g class="gr_ gr_38 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="38" data-gr-id="38">the .</g>pfx file to start the process.</p>



<figure class="wp-block-image"><img data-recalc-dims="1" decoding="async" width="547" height="526" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image-1.png?resize=547%2C526&#038;ssl=1" alt="" class="wp-image-4167" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image-1.png?w=547&amp;ssl=1 547w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image-1.png?resize=250%2C240&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image-1.png?resize=450%2C433&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image-1.png?resize=520%2C500&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image-1.png?resize=360%2C346&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/08/image-1.png?resize=100%2C96&amp;ssl=1 100w" sizes="(max-width: 547px) 100vw, 547px" /></figure>



<p>Next step, open <strong>RD Gateway Manager</strong>, right-click the server&#8217;s name and choose <strong>Properties</strong>. In the Properties dialog window, go to <strong>SSL Certificate tab</strong> and choose <strong>Import Certificate</strong>. </p>



<p>Pick the certificated I just imported earlier, click <strong>Import</strong> button.</p>



<p>Restarted the Gateway service and it&#8217;s all set.</p>The post <a href="https://www.kjctech.net/renewing-ssl-certificate-on-remote-desktop-gateway-server/">Renewing SSL Certificate on Remote Desktop Gateway Server</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/renewing-ssl-certificate-on-remote-desktop-gateway-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4165</post-id>	</item>
		<item>
		<title>Getting Client IP Addresses and its Geolocation from Remote Desktop Gateway Sessions</title>
		<link>https://www.kjctech.net/getting-client-ip-addresses-and-its-geolocation-from-remote-desktop-gateway-sessions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-client-ip-addresses-and-its-geolocation-from-remote-desktop-gateway-sessions</link>
					<comments>https://www.kjctech.net/getting-client-ip-addresses-and-its-geolocation-from-remote-desktop-gateway-sessions/#comments</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Mon, 23 Jul 2018 23:20:08 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[RD Gateway]]></category>
		<category><![CDATA[Remote Desktop Services]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=4138</guid>

					<description><![CDATA[<p>To get the IP addresses of the remote desktop sessions behind a Remote Desktop Gateway, you need to open RD Gateway Manager, go to Monitoring section and check each of the connected sessions to find their IP addresses. If you want to look further for their geolocations as well, you would search the IP address in one of the geolocation [&#8230;]</p>
The post <a href="https://www.kjctech.net/getting-client-ip-addresses-and-its-geolocation-from-remote-desktop-gateway-sessions/">Getting Client IP Addresses and its Geolocation from Remote Desktop Gateway Sessions</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>To get the IP addresses of the remote desktop sessions behind a Remote Desktop Gateway, you need to open <strong>RD Gateway Manager</strong>, go to <strong>Monitoring</strong> section and check each of the connected sessions to find their IP addresses. If you want to look further for their geolocations as well, you <g class="gr_ gr_31 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="31" data-gr-id="31">wou</g>ld search the IP address in one of the geolocation websites to find out.</p>



<p>That is just too many steps involved and there got to be a better way to handle this if I want to monitor all incoming remote sessions on a regular consistent basis. Time to ask PowerShell for help.</p>



<p>You can use <g class="gr_ gr_4 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep" id="4" data-gr-id="4">Get-WmiObject</g> cmdlet to query the Win32_TSGatewayConnection class for live session data on the Gateway server. Like this:</p>



<pre class="wp-block-preformatted">Get-WmiObject -class "Win32_TSGatewayConnection" -namespace "root\cimv2\TerminalServices" -ComputerName remote_server -Authentication 6</pre>



<figure class="wp-block-image"><img data-recalc-dims="1" decoding="async" width="640" height="403" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=640%2C403&#038;ssl=1" alt="" class="wp-image-4144" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?w=859&amp;ssl=1 859w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=250%2C157&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=450%2C283&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=768%2C484&amp;ssl=1 768w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=600%2C378&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=700%2C441&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=520%2C327&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=360%2C227&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image.png?resize=100%2C63&amp;ssl=1 100w" sizes="(max-width: 640px) 100vw, 640px" /></figure>



<p>To get the geolocation info, you can call up <strong>Invoke-RestMethod</strong> cmdlet that deals with HTTP/HTTPs&nbsp;requests related to Representational State Transfer (REST) web services that return richly structured data, such as XML or JSON. It’s a perfect candidate to perform the call and display the result in a nicely formatted way. It runs something like this:</p>



<pre class="wp-block-preformatted">Invoke-RestMethod -Uri "http://ipinfo.io/$ipaddress"</pre>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="523" height="313" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-1.png?resize=523%2C313&#038;ssl=1" alt="" class="wp-image-4145" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-1.png?w=523&amp;ssl=1 523w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-1.png?resize=250%2C150&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-1.png?resize=450%2C269&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-1.png?resize=520%2C311&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-1.png?resize=360%2C215&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/07/image-1.png?resize=100%2C60&amp;ssl=1 100w" sizes="auto, (max-width: 523px) 100vw, 523px" /></figure>



<p>For more information about getting Geolocation info from PowerShell, check out <a href="https://www.nextofwindows.com/getting-geo-location-of-any-ip-address-or-hostname-in-powershell">this post</a>.</p>



<p>Putting together, here is the code you can use to get all live sessions&#8217; IP addresses and their geolocation info on the Remote Gateway server.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">$ts = Get-WmiObject -class "Win32_TSGatewayConnection" -namespace "root\cimv2\TerminalServices" -ComputerName remote_server -Authentication 6
$ofs = "`r`n`r`n"
$body = "Gateway connections: " + $ofs

foreach ($connection in $ts)
{
    $username = $connection.username
    $ip = $connection.clientaddress
    $geo = Invoke-RestMethod -Uri "http://ipinfo.io/$ip"
    $body = $body + $connection.ConnectedTime + $username + $geo + $ofs
} 
$body</code></pre>



<p>It works great to get data from the live sessions. What about the closed sessions that you missed? You can create a scheduled task that triggers a PowerShell script every time a session goes live. The trigger needs to be based on the event, more specifically, Microsoft-Windows-TerminalServices-Gateway/Operational. See the trigger below:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="600" height="519" src="//i0.wp.com/kjctech.net/wp-content/uploads/2021/09/image-4-600x519.png" alt="" class="wp-image-4678" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2021/09/image-4.png?resize=600%2C519&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2021/09/image-4.png?resize=450%2C389&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2021/09/image-4.png?resize=250%2C216&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2021/09/image-4.png?resize=520%2C450&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2021/09/image-4.png?resize=360%2C311&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2021/09/image-4.png?resize=100%2C86&amp;ssl=1 100w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2021/09/image-4.png?w=605&amp;ssl=1 605w" sizes="auto, (max-width: 600px) 100vw, 600px" /></figure>



<p>The script will then collect the IP info of that session and save it to the event log.</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">$ts = Get-WmiObject -class "Win32_TSGatewayConnection" -namespace "root\cimv2\TerminalServices" -ComputerName Remote_Server -Authentication 6  | Sort-Object ConnectionDuration -Desc
$ofs = "`r`n`r`n"
$body = "Gateway connections: " + $ofs

foreach ($connection in $ts)
{
    $username = $connection.username
    $ip = $connection.clientaddress
    $geo = Invoke-RestMethod -Uri "http://ipinfo.io/$ip"
} 

$body = $body + $connection.ConnectedTime + ": " +$username + $geo + $ofs

$server = "remote_server"
$logname = "application"
#New-EventLog -ComputerName $server -Logname $logname -Source "MyApp"
Write-EventLog -ComputerName $server -Logname $logname -Source "MyApp" -EventID 3001 -Message $body</code></pre>



<p>Note that the script only extracts the last session from the session collection so only the newest info will be saved into the log. Once the data is saved in the event log, I can run another PowerShell script to collect and send them to me via email. And I can schedule that script to run on <g class="gr_ gr_4 gr-alert sel gr_gramm gr_replaced gr_inline_cards gr_disable_anim_appear Grammar only-ins replaceWithoutSep" id="4" data-gr-id="4">a </g>daily basis.</p>The post <a href="https://www.kjctech.net/getting-client-ip-addresses-and-its-geolocation-from-remote-desktop-gateway-sessions/">Getting Client IP Addresses and its Geolocation from Remote Desktop Gateway Sessions</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/getting-client-ip-addresses-and-its-geolocation-from-remote-desktop-gateway-sessions/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4138</post-id>	</item>
	</channel>
</rss>
