PoshCode Logo PowerShell Code Repository

Get-RDPSetting (modification of post by Jason Archer view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/678"></script>download | new post

Function/script to get the settings from a RDP file for Terminal Services.

Uncomment the function code to make a global function.

  1. ########################################################################################################################
  2. # NAME
  3. #     Get-RDPSetting
  4. #
  5. # SYNOPSIS
  6. #     Gets some (with filter) or all properties from a RDP file.
  7. #
  8. # SYNTAX
  9. #     Edit-RDP [-Path] <string> [-Name] <string> [[-Value] <object>] [-PassThru]
  10. #
  11. # DETAILED DESCRIPTION
  12. #     This retrieves the properties for a saved RDP connection from a RDP file.  The Name parameter can filter the
  13. #     list of properties to be returned.
  14. #
  15. # PARAMETERS
  16. #     -Path <string>
  17. #         Specifies the path to the RDP file.
  18. #
  19. #         Required?                    true
  20. #         Position?                    1
  21. #         Default value               
  22. #         Accept pipeline input?       false
  23. #         Accept wildcard characters?  false
  24. #
  25. #     -Name <string>
  26. #         Specifies the name of the property or properties to get.  Acts as a filter.
  27. #
  28. #         Required?                    false
  29. #         Position?                    2
  30. #         Default value               
  31. #         Accept pipeline input?       false
  32. #         Accept wildcard characters?  true
  33. #
  34. # INPUT TYPE
  35. #     
  36. #
  37. # RETURN TYPE
  38. #     System.Management.Automation.PSCustomObject#RDPConnectionSetting
  39. #
  40. # NOTES
  41. #
  42. #     -------------------------- EXAMPLE 1 --------------------------
  43. #
  44. #     C:\PS>Get-RDPSetting -Path C:\myserver.rdp
  45. #
  46. #
  47. #     This command gets all the properties of the "myserver" RDP file.
  48. #
  49. #
  50. #     -------------------------- EXAMPLE 2 --------------------------
  51. #
  52. #     C:\PS>Get-RDPSetting -Path C:\myserver.rdp -Name "r*"
  53. #
  54. #
  55. #     This command returns all the properties that start with "r" from the "myserver" RDP file.
  56. #
  57. #
  58.  
  59. #Function global:Get-RDPSetting {
  60.     param(
  61.         [string]$Path = $(throw "A path to a RDP file is required."),
  62.         [string]$Name = "*"
  63.     )
  64.  
  65.     $connection = Get-ChildItem -Path $path
  66.  
  67.     Get-Content -Path $Path | ForEach-Object {
  68.         [Void] ($_ -match '^([^:]*):([^:]*):(.*)$')
  69.         $settingname = $Matches[1]
  70.         $type = $Matches[2]
  71.         $value = $Matches[3]
  72.        
  73.         if ($settingname -like $Name) {
  74.             switch ($type) {
  75.                 'b' { $datatype = "byte[]" }
  76.                 'i' { $datatype = "integer" }
  77.                 default { $datatype = "string" }
  78.             }
  79.            
  80.             $object = "" | Select-Object Name,DataType,Value,Connection
  81.             $object.Name = $settingname
  82.             $object.DataType = $datatype
  83.             $object.Value = $value
  84.             $object.Connection = $connection.FullName
  85.             $object.PSObject.TypeNames.Insert(0,"$($object.PSObject.TypeNames[0])#RDPConnectionSetting")
  86.             $object
  87.         }
  88.     }
  89. #}

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me