Bonjour

Le but de mon script est de me connecter facilement en écran partager avec les nouvelles fonctionnalités (depuis Windows 2012) de MSTSC pour dépanner les utilisateurs du serveur RDS.

J'ai ecris le code ci-dessous qui fonctionne.
Mais j'aurai aimer avoir une liste déroulante à la place de la listview.

Je me suis heurté à un problème d'affichage car dans le combobox je n'es pas su afficher plusieurs colonnes.
Donc si vous avez des pistes?

une vue de l'interface
Nom : MSTSC Shadow.png
Affichages : 457
Taille : 34,2 Ko

Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
 
 
	#region Import the Assemblies
	[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
	[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
	#endregion
 
	#region Generated Form Objects
	$Main = New-Object System.Windows.Forms.Form
	$Chk_NoConsentPrompt = New-Object System.Windows.Forms.CheckBox
	$Chk_Control = New-Object System.Windows.Forms.CheckBox
	$Txt_RDS = New-Object System.Windows.Forms.TextBox
	$Lab_RDS = New-Object System.Windows.Forms.Label
	$Lvw_User = New-Object System.Windows.Forms.ListView
	$But_Connection = New-Object System.Windows.Forms.Button
	$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
	#endregion Generated Form Objects
 
	#----------------------------------------------
	#Generated Event Script Blocks
	#----------------------------------------------
	#Provide Custom Code for events specified in PrimalForms.
 
 
	Function fGet-RDUserSession {
		Param (
			[Parameter(Mandatory=$true)][string]$ServerName
		)
 
		$RDCollection = "QuickSessionCollection"
 
		return Get-RDUserSession -CollectionName $RDCollection -ConnectionBroker $ServerName | Select UnifiedSessionId, UserName | Sort UserName
 
	}
 
	$OnLoadForm_StateCorrection	= {
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$Main.WindowState = $InitialFormWindowState
 
        foreach ($RDUserSession in fGet-RDUserSession $Txt_RDS.Text) {
            $ItemParam = New-Object System.Windows.Forms.ListViewItem($RDUserSession.UnifiedSessionId)
            $ItemParam.SubItems.Add($RDUserSession.UserName)
            $Lvw_User.Items.Add($ItemParam)
        }
 
        $Lvw_User.AutoResizeColumns([System.Windows.Forms.ColumnHeaderAutoResizeStyle]::HeaderSize)
 
	}
 
       $Connection = {
 
        $Option = ""
 
        if ($Chk_Control.Checked -and $Chk_NoConsentPrompt.Checked) {
 
             MSTSC /SHADOW:$($Lvw_User.SelectedItems.Item(0).text) /V:$($Txt_RDS.Text) /Control /NoConsentPrompt
 
        } elseif ($Chk_NoConsentPrompt.Checked) {
 
            MSTSC /SHADOW:$($Lvw_User.SelectedItems.Item(0).text) /V:$($Txt_RDS.Text) /NoConsentPrompt
 
        } elseif ($Chk_Control.Checked) {
 
            MSTSC /SHADOW:$($Lvw_User.SelectedItems.Item(0).text) /V:$($Txt_RDS.Text) /Control
 
        }
 
    }
 
 
	#----------------------------------------------
	#region Generated Form Code
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 430
	$System_Drawing_Size.Width = 330
	$Main.ClientSize = $System_Drawing_Size
	$Main.DataBindings.DefaultDataSourceUpdateMode = 0
	$Main.FormBorderStyle = 1
	$Main.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon('C:\Scripts\RDS\Icon-Main.ico')
	$Main.MaximizeBox = $False
	$Main.MinimizeBox = $False
	$Main.Name = "Main"
	$Main.Text = "MSTSC /Shadow"
	#$Main.add_Load(fGet-RDUserSession)
 
 
	$Chk_NoConsentPrompt.DataBindings.DefaultDataSourceUpdateMode = 0
	$Chk_NoConsentPrompt.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8,0,3,0)
 
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 13
	$System_Drawing_Point.Y = 380
	$Chk_NoConsentPrompt.Location = $System_Drawing_Point
	$Chk_NoConsentPrompt.Name = "Chk_NoConsentPrompt"
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 32
	$System_Drawing_Size.Width = 300
	$Chk_NoConsentPrompt.Size = $System_Drawing_Size
	$Chk_NoConsentPrompt.TabIndex = 8
	$Chk_NoConsentPrompt.Text = "Ne pas demander l`'accord de l`'utilisateur"
	$Chk_NoConsentPrompt.UseVisualStyleBackColor = $True
 
	$Main.Controls.Add($Chk_NoConsentPrompt)
 
 
	$Chk_Control.Checked = $True
	$Chk_Control.CheckState = 1
	$Chk_Control.DataBindings.DefaultDataSourceUpdateMode = 0
 
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 13
	$System_Drawing_Point.Y = 360
	$Chk_Control.Location = $System_Drawing_Point
	$Chk_Control.Name = "Chk_Control"
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 24
	$System_Drawing_Size.Width = 300
	$Chk_Control.Size = $System_Drawing_Size
	$Chk_Control.TabIndex = 7
	$Chk_Control.Text = "Permettre le controle à distance"
	$Chk_Control.UseVisualStyleBackColor = $True
	$Chk_Control.add_CheckedChanged($handler_checkBox1_CheckedChanged)
 
	$Main.Controls.Add($Chk_Control)
 
	$Txt_RDS.DataBindings.DefaultDataSourceUpdateMode = 0
	$Txt_RDS.Enabled = $False
	$Txt_RDS.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)
	$Txt_RDS.ForeColor = [System.Drawing.Color]::FromArgb(255,0,102,204)
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 13
	$System_Drawing_Point.Y = 31
	$Txt_RDS.Location = $System_Drawing_Point
	$Txt_RDS.Name = "Txt_RDS"
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 20
	$System_Drawing_Size.Width = 300
	$Txt_RDS.Size = $System_Drawing_Size
	$Txt_RDS.TabIndex = 6
	$Txt_RDS.Text = "SERVEUR.DOM.LOCAL"
	$Txt_RDS.TextAlign = 2
 
	$Main.Controls.Add($Txt_RDS)
 
	$Lab_RDS.DataBindings.DefaultDataSourceUpdateMode = 0
 
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 13
	$System_Drawing_Point.Y = 13
	$Lab_RDS.Location = $System_Drawing_Point
	$Lab_RDS.Name = "Lab_RDS"
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 23
	$System_Drawing_Size.Width = 300
	$Lab_RDS.Size = $System_Drawing_Size
	$Lab_RDS.TabIndex = 5
	$Lab_RDS.Text = "Connexion au serveur"
 
	$Main.Controls.Add($Lab_RDS)
 
	$Lvw_User.DataBindings.DefaultDataSourceUpdateMode = 0
 
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 13
	$System_Drawing_Point.Y = 70
	$Lvw_User.Location = $System_Drawing_Point
	$Lvw_User.Name = "Lvw_User"
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 250
	$System_Drawing_Size.Width = 300
	$Lvw_User.Size = $System_Drawing_Size
	$Lvw_User.TabIndex = 4
        $Lvw_User.Columns.Add("UnifiedSessionId") | Out-Null
        $Lvw_User.Columns.Add("UserName") | Out-Null
        $Lvw_User.GridLines = $true
        $Lvw_User.FullRowSelect = $true
        $Lvw_User.View = "Details"
        $Lvw_User.MultiSelect = $False
 
	$Main.Controls.Add($Lvw_User)
 
 
	$But_Connection.DataBindings.DefaultDataSourceUpdateMode = 0
 
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 13
	$System_Drawing_Point.Y = 330
	$But_Connection.Location = $System_Drawing_Point
	$But_Connection.Name = "But_Connection"
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 23
	$System_Drawing_Size.Width = 300
	$But_Connection.Size = $System_Drawing_Size
	$But_Connection.TabIndex = 3
	$But_Connection.Text = "Connexion"
	$But_Connection.UseVisualStyleBackColor = $True
	$But_Connection.add_Click($Connection)
 
	$Main.Controls.Add($But_Connection)
 
 
	#endregion Generated Form Code
 
 
    	#Save the initial state of the form
	$InitialFormWindowState = $Main.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$Main.add_Load($OnLoadForm_StateCorrection)
	#Show the Form
	$Main.ShowDialog()| Out-Null