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

Report this snippet  

You need to login to post a comment.