Bonjour à toutes et à tous,

Je me permet de vous solliciter car je suis bloqué sur un programme que je développe en Powershell.

Pour ma société, je développe un petit programme qui permet de déplacer un ordinateur (sélectionné depuis un combobox) qui se situe dans l'OU Computers vers une autre OU (que l'on a sélectionné dans une ComboBox), on lui rajoute ces groupes ainsi qu'une description.

Je ne me suis pas encore attaqué aux groupes pour le moment par contre j'arrive à leur mettre une description depuis le programme mais le gros problème réside que je n'arrive pas à faire déplace l'ordinateur vers l'ou sélectionné.

voici mon programme

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
#Importation du module Active Directory.
import-module activedirectory
 
#Ouvre une fenêtre.
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$form1 = New-Object Windows.Forms.Form
$form1.text = "Gestion Ordinateurs"             
$form1.Size = New-Object System.Drawing.Size(400,400)
 
# Création du bouton Cancel
$ButtonCancel = New-Object System.Windows.Forms.Button
$ButtonCancel.Location = New-Object System.Drawing.Point(250,320)
$ButtonCancel.Size = New-Object System.Drawing.Size(75,23)
$ButtonCancel.Text = "Annuler"
$ButtonCancel.DialogResult = [system.Windows.Forms.DialogResult]::Cancel
 
# Création d'un label
$FormLabel1 = New-Object System.Windows.Forms.Label
$FormLabel1.Location = New-Object System.Drawing.Point(10,10)
$FormLabel1.Size = New-Object System.Drawing.Size(120,23)
$FormLabel1.Text = " Nom de l'ordinateur : "
 
$FormLabel2 = New-Object System.Windows.Forms.Label
$FormLabel2.Location = New-Object System.Drawing.Point(10,70)
$FormLabel2.Size = New-Object System.Drawing.Size(120,23)
$FormLabel2.Text = " Ranger dans l'OU : "
 
$FormLabel3 = New-Object System.Windows.Forms.Label
$FormLabel3.Location = New-Object System.Drawing.Point(10,130)
$FormLabel3.Size = New-Object System.Drawing.Size(150,23)
$FormLabel3.Text = " Description de l'ordinateur : "
 
$FormLabel4 = New-Object System.Windows.Forms.Label
$FormLabel4.Location = New-Object System.Drawing.Point(10,190)
$FormLabel4.Size = New-Object System.Drawing.Size(205,23)
$FormLabel4.Text = " Groupe d'impression pour l'ordinateur : "
 
$FormLabel5 = New-Object System.Windows.Forms.Label
$FormLabel5.Location = New-Object System.Drawing.Point(10,250)
$FormLabel5.Size = New-Object System.Drawing.Size(205,23)
$FormLabel5.Text = " Autre groupe pour l'ordinateur : "
 
$Computer = Get-ADComputer -LDAPFilter '(name=*)' -SearchBase "CN=Computers,DC="domaine",DC=fr"
$Computer = $Computer.Name
 
#Création de la Textbox
$FormTextBox1 = New-Object System.Windows.Forms.ComboBox
$FormTextBox1.Location = New-Object System.Drawing.Point(15,35)
$FormTextBox1.Size = New-Object System.Drawing.Size(100,10)
$FormTextBox1.Height = 20
 
#Pour afficher par ordre alphabétique
$FormTextBox1.Sorted = $true
 
#La combobox sera en menu déroulant descendant
$FormTextBox1.DropDownStyle = "DropDownList"
 
#Retourne les valeurs récupérées dans la variable $OU dans la combobox
foreach($ComputerList in $Computer)
{
  $FormTextBox1.Items.add($ComputerList)
}
 
$FormTextBox2 = New-Object System.Windows.Forms.TextBox
$FormTextBox2.Location = New-Object System.Drawing.Point(15,155)
$FormTextBox2.Size = New-Object System.Drawing.Size(200,10)
$FormTextBox2.Height = 20
 
# Création du bouton Ok
$ButtonOK = New-Object System.Windows.Forms.Button
$ButtonOK.Location = New-Object System.Drawing.Point(50,320)
$ButtonOK.Size = New-Object System.Drawing.Size(75,23)
$ButtonOK.Text = "Ok"
$ButtonOK.DialogResult = [system.Windows.Forms.DialogResult]::Ok
#Action lors du clic de bouton Ok
$ButtonOK.Add_Click({ordi})
 
#Récupération des OU de notre AD
$OU = Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase 'OU=Postes Clients,OU=...,DC="domaine",DC=fr'
$OU = $OU.Name
 
#Liste deroulante (ComboBox)
$FormComboBox1 = New-Object System.Windows.Forms.Combobox
$FormComboBox1.Location = New-Object Drawing.Point (15,95)
$FormComboBox1.Size = New-Object System.Drawing.Size(200,10)
 
#Pour afficher par ordre alphabétique
$FormComboBox1.Sorted = $true
 
#La combobox sera en menu déroulant descendant
$FormComboBox1.DropDownStyle = "DropDownList"
 
#Retourne les valeurs récupérées dans la combobox
foreach($OUList in $OU)
{
  $FormComboBox1.Items.add($OUList)
 
}
 
$GroupeImpression = Get-ADGroup -Filter "*" -SearchBase 'OU=Groupes_Impression,OU=...,DC="domaine",DC=fr'
$GroupeImpression = $GroupeImpression.name
 
#Liste deroulante (ComboBox)
$FormComboBox2 = New-Object System.Windows.Forms.Combobox
$FormComboBox2.Location = New-Object Drawing.Point (15,215)
$FormComboBox2.Size = New-Object System.Drawing.Size(200,10)
 
#Pour afficher par ordre alphabétique
$FormComboBox2.Sorted = $true
 
$FormComboBox2.DropDownStyle = "DropDownList"
 
#Retourne les valeurs récupérées dans la combobox
foreach($GroupeImpressionList in $GroupeImpression)
{
  $FormComboBox2.Items.add($GroupeImpressionList)
}
 
$GroupeOther = Get-ADGroup -Filter "*" -SearchBase 'CN=G_724Poste,OU=...,DC="domaine",DC=fr'
$GroupeOther = $GroupeOther.Name
 
#Liste deroulante (ComboBox)
$FormComboBox3 = New-Object System.Windows.Forms.Combobox
$FormComboBox3.Location = New-Object Drawing.Point (15,275)
$FormComboBox3.Size = New-Object System.Drawing.Size(200,10)
 
#Pour afficher par ordre alphabétique
$FormComboBox3.Sorted = $true
 
$FormComboBox3.DropDownStyle = "DropDownList"
 
#Retourne les valeurs récupérées dans la combobox
foreach($GroupeOtherList in $GroupeOther)
{
  $FormComboBox3.Items.add($GroupeOtherList)
}
 
function ordi {
Get-ADObject -Identity $FormTextBox1.SelectedItem | %{Move-ADObject -targetpath $FormComboBox1.SelectedItem}
 
Set-ADComputer $FormTextBox1.SelectedItem -Description $FormTextBox2.Text
 
Write-Host "Le poste "$FormTextBox1.SelectedItem" a été mis dans l'OU "$FormComboBox1.SelectedItem," a pour description " $FormTextBox2.Text
}
 
$form1.controls.add($ButtonCancel)
$form1.controls.add($ButtonOK)
$form1.controls.add($FormLabel1)
$form1.controls.add($FormLabel2)
$form1.controls.add($FormLabel3)
$form1.controls.add($FormLabel4)
$form1.controls.add($FormLabel5)
$form1.controls.add($FormTextBox1)
$form1.controls.add($FormTextBox2)
$form1.controls.add($FormComboBox1)
$form1.controls.add($FormComboBox2)
$form1.controls.add($FormComboBox3)
 
#Affiche le tout.
$form1.ShowDialog()
#Fin.

Voici l'erreur que je rencontre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
Get-ADObject : Impossible de trouver un objet avec l’identité «TESTJG» sous: «
DC="domaine",DC=fr».
Au caractère C:\Users\jgrudzien\Documents\SAPIEN\Scripts\test.ps1:139 : 1
+ Get-ADObject -Identity $FormTextBox1.SelectedItem | %{Move-ADObject - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (TESTJG:ADObject) [Get-ADObject], ADIdentit 
   yNotFoundException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management. 
   ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADObject
TESTJG est le nom du pc que je récupérer dans la FormTextBox (attention je n'ai pas modifier mais il s'agit d'un combobox en réalité) et ce poste existe bien dans notre Active directory.

Le soucis est que je n'arrive pas à régler le problème, j'ai cherché un peu partout sur le net, tester divers ligne de commande rien.

Merci d'avance de l'aide que vous m'apporterez.