Posted By

foobartn on 08/20/14


Tagged

windows posh PowerShell RDP


Versions (?)

New-RDCManFile


 / Published in: Windows PowerShell
 

##################################################################### NAME: New-RDCManFile.ps1 AUTHOR: Jan Egil Ring EMAIL: [email protected] COMMENT: Script to create a XML-file for use with Microsoft Remote Desktop Connection Manager For more details, see the following blog-post: http://blog.powershell.no/2010/06/02/dynamic-remote-desktop-connection-manager-connection-list You have a royalty-free right to use, modify, reproduce, and distribute this script file in any way you find useful, provided that you agree that the creator, owner above has no warranty, obligations, or liability for such use. VERSION HISTORY: 1.0 02.06.2010 - Initial release 1.1 02.25.2013 - edited by Joshua Barton #
  1. ###########################################################################
  2. #
  3. # NAME: New-RDCManFile.ps1
  4. #
  5. # AUTHOR: Jan Egil Ring
  6. #
  7. # COMMENT: Script to create a XML-file for use with Microsoft Remote Desktop Connection Manager
  8. # For more details, see the following blog-post: http://blog.powershell.no/2010/06/02/dynamic-remote-desktop-connection-manager-connection-list
  9. #
  10. # You have a royalty-free right to use, modify, reproduce, and
  11. # distribute this script file in any way you find useful, provided that
  12. # you agree that the creator, owner above has no warranty, obligations,
  13. # or liability for such use.
  14. #
  15. # VERSION HISTORY:
  16. # 1.0 02.06.2010 - Initial release
  17. # 1.1 02.25.2013 - edited by Joshua Barton
  18.  
  19. #
  20. ###########################################################################
  21.  
  22. #Importing Microsoft`s PowerShell-module for administering ActiveDirectory
  23. Import-Module ActiveDirectory
  24.  
  25. #Initial variables
  26. $domain = $env:userdomain
  27. $OutputFile = "c:\$domain.rdg"
  28.  
  29. #Create a template XML
  30. $template = @'
  31. <?xml version="1.0" encoding="utf-8"?>
  32. <RDCMan schemaVersion="1">
  33. <version>2.2</version>
  34. <file>
  35. <properties>
  36. <name></name>
  37. <expanded>True</expanded>
  38. <comment />
  39. <logonCredentials inherit="None">
  40. <userName></userName>
  41. <domain></domain>
  42. <password storeAsClearText="False"></password>
  43. </logonCredentials>
  44. <connectionSettings inherit="FromParent" />
  45. <gatewaySettings inherit="FromParent" />
  46. <remoteDesktop inherit="FromParent" />
  47. <localResources inherit="FromParent" />
  48. <securitySettings inherit="FromParent" />
  49. <displaySettings inherit="FromParent" />
  50. </properties>
  51. <group>
  52. <properties>
  53. <name>Administrative</name>
  54. <expanded>True</expanded>
  55. <comment />
  56. <logonCredentials inherit="FromParent" />
  57. <connectionSettings inherit="FromParent" />
  58. <gatewaySettings inherit="None">
  59. <userName></userName>
  60. <domain></domain>
  61. <password storeAsClearText="False" />
  62. <enabled>False</enabled>
  63. <hostName />
  64. <logonMethod>4</logonMethod>
  65. <localBypass>False</localBypass>
  66. <credSharing>False</credSharing>
  67. </gatewaySettings>
  68. <remoteDesktop inherit="FromParent" />
  69. <localResources inherit="FromParent" />
  70. <securitySettings inherit="FromParent" />
  71. <displaySettings inherit="FromParent" />
  72. </properties>
  73. <server>
  74. <name></name>
  75. <displayName></displayName>
  76. <comment />
  77. <logonCredentials inherit="FromParent" />
  78. <connectionSettings inherit="FromParent" />
  79. <gatewaySettings inherit="FromParent" />
  80. <remoteDesktop inherit="FromParent" />
  81. <localResources inherit="FromParent" />
  82. <securitySettings inherit="FromParent" />
  83. <displaySettings inherit="FromParent" />
  84. </server>
  85. </group>
  86. <group>
  87. <properties>
  88. <name>Application</name>
  89. <expanded>True</expanded>
  90. <comment />
  91. <logonCredentials inherit="FromParent" />
  92. <connectionSettings inherit="FromParent" />
  93. <gatewaySettings inherit="None">
  94. <userName></userName>
  95. <domain></domain>
  96. <password storeAsClearText="False" />
  97. <enabled>False</enabled>
  98. <hostName />
  99. <logonMethod>4</logonMethod>
  100. <localBypass>False</localBypass>
  101. <credSharing>False</credSharing>
  102. </gatewaySettings>
  103. <remoteDesktop inherit="FromParent" />
  104. <localResources inherit="FromParent" />
  105. <securitySettings inherit="FromParent" />
  106. <displaySettings inherit="FromParent" />
  107. </properties>
  108. <server>
  109. <name></name>
  110. <displayName></displayName>
  111. <comment />
  112. <logonCredentials inherit="FromParent" />
  113. <connectionSettings inherit="FromParent" />
  114. <gatewaySettings inherit="FromParent" />
  115. <remoteDesktop inherit="FromParent" />
  116. <localResources inherit="FromParent" />
  117. <securitySettings inherit="FromParent" />
  118. <displaySettings inherit="FromParent" />
  119. </server>
  120. </group>
  121. <group>
  122. <properties>
  123. <name>Cifs</name>
  124. <expanded>True</expanded>
  125. <comment />
  126. <logonCredentials inherit="FromParent" />
  127. <connectionSettings inherit="FromParent" />
  128. <gatewaySettings inherit="None">
  129. <userName></userName>
  130. <domain></domain>
  131. <password storeAsClearText="False" />
  132. <enabled>False</enabled>
  133. <hostName />
  134. <logonMethod>4</logonMethod>
  135. <localBypass>False</localBypass>
  136. <credSharing>False</credSharing>
  137. </gatewaySettings>
  138. <remoteDesktop inherit="FromParent" />
  139. <localResources inherit="FromParent" />
  140. <securitySettings inherit="FromParent" />
  141. <displaySettings inherit="FromParent" />
  142. </properties>
  143. <server>
  144. <name></name>
  145. <displayName></displayName>
  146. <comment />
  147. <logonCredentials inherit="FromParent" />
  148. <connectionSettings inherit="FromParent" />
  149. <gatewaySettings inherit="FromParent" />
  150. <remoteDesktop inherit="FromParent" />
  151. <localResources inherit="FromParent" />
  152. <securitySettings inherit="FromParent" />
  153. <displaySettings inherit="FromParent" />
  154. </server>
  155. </group>
  156. <group>
  157. <properties>
  158. <name>Citrix</name>
  159. <expanded>True</expanded>
  160. <comment />
  161. <logonCredentials inherit="FromParent" />
  162. <connectionSettings inherit="FromParent" />
  163. <gatewaySettings inherit="None">
  164. <userName></userName>
  165. <domain></domain>
  166. <password storeAsClearText="False" />
  167. <enabled>False</enabled>
  168. <hostName />
  169. <logonMethod>4</logonMethod>
  170. <localBypass>False</localBypass>
  171. <credSharing>False</credSharing>
  172. </gatewaySettings>
  173. <remoteDesktop inherit="FromParent" />
  174. <localResources inherit="FromParent" />
  175. <securitySettings inherit="FromParent" />
  176. <displaySettings inherit="FromParent" />
  177. </properties>
  178. <server>
  179. <name></name>
  180. <displayName></displayName>
  181. <comment />
  182. <logonCredentials inherit="FromParent" />
  183. <connectionSettings inherit="FromParent" />
  184. <gatewaySettings inherit="FromParent" />
  185. <remoteDesktop inherit="FromParent" />
  186. <localResources inherit="FromParent" />
  187. <securitySettings inherit="FromParent" />
  188. <displaySettings inherit="FromParent" />
  189. </server>
  190. </group>
  191. <group>
  192. <properties>
  193. <name>Database</name>
  194. <expanded>True</expanded>
  195. <comment />
  196. <logonCredentials inherit="FromParent" />
  197. <connectionSettings inherit="FromParent" />
  198. <gatewaySettings inherit="None">
  199. <userName></userName>
  200. <domain></domain>
  201. <password storeAsClearText="False" />
  202. <enabled>False</enabled>
  203. <hostName />
  204. <logonMethod>4</logonMethod>
  205. <localBypass>False</localBypass>
  206. <credSharing>False</credSharing>
  207. </gatewaySettings>
  208. <remoteDesktop inherit="FromParent" />
  209. <localResources inherit="FromParent" />
  210. <securitySettings inherit="FromParent" />
  211. <displaySettings inherit="FromParent" />
  212. </properties>
  213. <server>
  214. <name></name>
  215. <displayName></displayName>
  216. <comment />
  217. <logonCredentials inherit="FromParent" />
  218. <connectionSettings inherit="FromParent" />
  219. <gatewaySettings inherit="FromParent" />
  220. <remoteDesktop inherit="FromParent" />
  221. <localResources inherit="FromParent" />
  222. <securitySettings inherit="FromParent" />
  223. <displaySettings inherit="FromParent" />
  224. </server>
  225. </group>
  226. <group>
  227. <properties>
  228. <name>Exchange</name>
  229. <expanded>True</expanded>
  230. <comment />
  231. <logonCredentials inherit="FromParent" />
  232. <connectionSettings inherit="FromParent" />
  233. <gatewaySettings inherit="None">
  234. <userName></userName>
  235. <domain></domain>
  236. <password storeAsClearText="False" />
  237. <enabled>False</enabled>
  238. <hostName />
  239. <logonMethod>4</logonMethod>
  240. <localBypass>False</localBypass>
  241. <credSharing>False</credSharing>
  242. </gatewaySettings>
  243. <remoteDesktop inherit="FromParent" />
  244. <localResources inherit="FromParent" />
  245. <securitySettings inherit="FromParent" />
  246. <displaySettings inherit="FromParent" />
  247. </properties>
  248. <server>
  249. <name></name>
  250. <displayName></displayName>
  251. <comment />
  252. <logonCredentials inherit="FromParent" />
  253. <connectionSettings inherit="FromParent" />
  254. <gatewaySettings inherit="FromParent" />
  255. <remoteDesktop inherit="FromParent" />
  256. <localResources inherit="FromParent" />
  257. <securitySettings inherit="FromParent" />
  258. <displaySettings inherit="FromParent" />
  259. </server>
  260. </group>
  261. <group>
  262. <properties>
  263. <name>Security</name>
  264. <expanded>True</expanded>
  265. <comment />
  266. <logonCredentials inherit="FromParent" />
  267. <connectionSettings inherit="FromParent" />
  268. <gatewaySettings inherit="None">
  269. <userName></userName>
  270. <domain></domain>
  271. <password storeAsClearText="False" />
  272. <enabled>False</enabled>
  273. <hostName />
  274. <logonMethod>4</logonMethod>
  275. <localBypass>False</localBypass>
  276. <credSharing>False</credSharing>
  277. </gatewaySettings>
  278. <remoteDesktop inherit="FromParent" />
  279. <localResources inherit="FromParent" />
  280. <securitySettings inherit="FromParent" />
  281. <displaySettings inherit="FromParent" />
  282. </properties>
  283. <server>
  284. <name></name>
  285. <displayName></displayName>
  286. <comment />
  287. <logonCredentials inherit="FromParent" />
  288. <connectionSettings inherit="FromParent" />
  289. <gatewaySettings inherit="FromParent" />
  290. <remoteDesktop inherit="FromParent" />
  291. <localResources inherit="FromParent" />
  292. <securitySettings inherit="FromParent" />
  293. <displaySettings inherit="FromParent" />
  294. </server>
  295. </group>
  296. <group>
  297. <properties>
  298. <name>Vendor Supported</name>
  299. <expanded>True</expanded>
  300. <comment />
  301. <logonCredentials inherit="FromParent" />
  302. <connectionSettings inherit="FromParent" />
  303. <gatewaySettings inherit="None">
  304. <userName></userName>
  305. <domain></domain>
  306. <password storeAsClearText="False" />
  307. <enabled>False</enabled>
  308. <hostName />
  309. <logonMethod>4</logonMethod>
  310. <localBypass>False</localBypass>
  311. <credSharing>False</credSharing>
  312. </gatewaySettings>
  313. <remoteDesktop inherit="FromParent" />
  314. <localResources inherit="FromParent" />
  315. <securitySettings inherit="FromParent" />
  316. <displaySettings inherit="FromParent" />
  317. </properties>
  318. <server>
  319. <name></name>
  320. <displayName></displayName>
  321. <comment />
  322. <logonCredentials inherit="FromParent" />
  323. <connectionSettings inherit="FromParent" />
  324. <gatewaySettings inherit="FromParent" />
  325. <remoteDesktop inherit="FromParent" />
  326. <localResources inherit="FromParent" />
  327. <securitySettings inherit="FromParent" />
  328. <displaySettings inherit="FromParent" />
  329. </server>
  330. </group>
  331. <group>
  332. <properties>
  333. <name>Web</name>
  334. <expanded>True</expanded>
  335. <comment />
  336. <logonCredentials inherit="FromParent" />
  337. <connectionSettings inherit="FromParent" />
  338. <gatewaySettings inherit="None">
  339. <userName></userName>
  340. <domain></domain>
  341. <password storeAsClearText="False" />
  342. <enabled>False</enabled>
  343. <hostName />
  344. <logonMethod>4</logonMethod>
  345. <localBypass>False</localBypass>
  346. <credSharing>False</credSharing>
  347. </gatewaySettings>
  348. <remoteDesktop inherit="FromParent" />
  349. <localResources inherit="FromParent" />
  350. <securitySettings inherit="FromParent" />
  351. <displaySettings inherit="FromParent" />
  352. </properties>
  353. <server>
  354. <name></name>
  355. <displayName></displayName>
  356. <comment />
  357. <logonCredentials inherit="FromParent" />
  358. <connectionSettings inherit="FromParent" />
  359. <gatewaySettings inherit="FromParent" />
  360. <remoteDesktop inherit="FromParent" />
  361. <localResources inherit="FromParent" />
  362. <securitySettings inherit="FromParent" />
  363. <displaySettings inherit="FromParent" />
  364. </server>
  365. </group>
  366. </file>
  367. </RDCMan>
  368. '@
  369.  
  370. #Output template to xml-file
  371. $template | Out-File C:\RDCMan-template.xml -encoding UTF8
  372.  
  373. #Load template into XML object
  374. $xml = New-Object xml
  375. $xml.Load("C:\RDCMan-template.xml")
  376.  
  377. #Set file properties
  378. $file = (@($xml.RDCMan.file.properties)[0]).Clone()
  379. $file.name = $domain
  380. $file.logonCredentials.Username = $env:username
  381. $file.logonCredentials.Domain = $domain
  382. $xml.RDCMan.file.properties | Where-Object { $_\3.Name -eq "" } | ForEach-Object { [void]$xml.RDCMan.file.ReplaceChild($file,$_\3) }
  383.  
  384. $groupNum = 0
  385. $serverGroups = @("Administrative","Application","Cifs","Citrix","Database","Exchange","Security","Vendor Supported","Web")
  386.  
  387. Foreach ($serverGroup in $serverGroups) {
  388. $groupTemplate = (@($xml.RDCMan.file.group[$groupNum].properties)[0]).Clone()
  389. $serverTemplate = (@($xml.RDCMan.file.group[$groupNum].server)[0]).Clone()
  390.  
  391. Get-ADComputer -LDAPFilter "(operatingsystem=*server*)" | ? {$_\3.DistinguishedName -Match "$serverGroup" } | select name,dnshostname |
  392.  
  393. ForEach-Object {
  394. $server = $serverTemplate.clone()
  395. $server.DisplayName = $_\3.Name
  396. $server.Name = $_\3.DNSHostName
  397. $xml.RDCMan.file.group[$groupNum].AppendChild($server) > $null}
  398.  
  399. #Remove template server
  400. $xml.RDCMan.file.group[$groupNum].server | Where-Object { $_\3.Name -eq "" } | ForEach-Object { [void]$xml.RDCMan.file.group[$groupNum].RemoveChild($_\3) }
  401.  
  402.  
  403. $groupNum++
  404. }
  405.  
  406. #Save xml to file
  407. $xml.Save($OutputFile)
  408.  
  409. #Remove template xml-file
  410. Remove-Item C:\RDCMan-template.xml -Force

Report this snippet  

You need to login to post a comment.