{"id":2845,"date":"2018-05-18T11:11:08","date_gmt":"2018-05-18T10:11:08","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=2845"},"modified":"2018-05-18T11:11:08","modified_gmt":"2018-05-18T10:11:08","slug":"getting-remoteapps-through-vm-custom-extension-on-azure-session-brokers","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2018\/05\/getting-remoteapps-through-vm-custom-extension-on-azure-session-brokers\/","title":{"rendered":"Getting remoteapps through vm custom extension on Azure session brokers"},"content":{"rendered":"<p>So I wanted to retrieve the remoteapps present on VM&#8217;s in a uniform way, without logging in to either VM&#8217;s or database.<\/p>\n<p>Using a custom extension, I tried to execute the Get-RDRemoteApp command and got the following:<\/p>\n<blockquote><p>Get-RDRemoteApp : A Remote Desktop Services deployment does not exist on\u00a0<i>server<\/i>. This operation can be perfor<br \/>\nmed after creating a deployment. For information about creating a deployment<\/p><\/blockquote>\n<p>Apparently, all the powershell commands for RDS require that you DON&#8217;T run them under SYSTEM. Of course VMExtensions run under SYSTEM. So, to get all remoteapps in a RDS deployment, execute the following Powershell script as VMExtension on a connection broker VM:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">$farms = get-childitem &quot;HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Terminal Server\\CentralPublishedResources\\PublishedFarms&quot;\nforeach($farm in $farms){\n    (get-childItem &quot;HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Terminal Server\\CentralPublishedResources\\PublishedFarms\\$($farm.PSChildName)\\Applications&quot;).PSChildName\n}\n<\/pre>\n<p>To register this Powershell script as a VM extension and retrieve the results<\/p>\n<ol>\n<li>Save the above PS code to a file<\/li>\n<li>Upload the file somewhere (e.g. public blob storage)<\/li>\n<li>Get the URL of the File<\/li>\n<li>Use Login-AzureRMAccount<\/li>\n<li>Execute\u00a0Set-AzureRmVMCustomScriptExtension -FileUri URL TO SCRIPT -Run FILENAME OF SCRIPT -VMName VMNAME -Name &#8220;RetrieveRemoteApps&#8221; -ResourceGroupName RESOURCEGROUP NAME -location &#8220;westeurope&#8221; -ForceRerun $(New-Guid).Guid<\/li>\n<li>To retrieve the list (after execution): [regex]::Replace(((Get-AzureRmVMDiagnosticsExtension -ResourceGroupName RESOURCEGROUP NAME -VMName VM NAME -Name &#8220;RetrieveRemoteApps&#8221; -Status).SubStatuses[0].Message), &#8220;\\\\n&#8221;, &#8220;`n&#8221;)<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>So I wanted to retrieve the remoteapps present on VM&#8217;s in a uniform way, without logging in to either VM&#8217;s or database. Using a custom extension, I tried to execute the Get-RDRemoteApp command and got the following: Get-RDRemoteApp : A Remote Desktop Services deployment does not exist on\u00a0server. This operation can be perfor med after &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2018\/05\/getting-remoteapps-through-vm-custom-extension-on-azure-session-brokers\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Getting remoteapps through vm custom extension on Azure session brokers<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[4,5,39],"tags":[],"class_list":["post-2845","post","type-post","status-publish","format-standard","hentry","category-automation","category-azure","category-powershell"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/2845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=2845"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/2845\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=2845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=2845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=2845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}