IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Script GUI On KeyUp


Sujet :

Scripts/Batch

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    816
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 816
    Points : 49
    Points
    49
    Par défaut Script GUI On KeyUp
    Bonjour à tous,

    je prépare un script PowerShell GUI que voici et je bloque sur certain point.

    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
    ]Import-Module ActiveDirectory
    Add-Type -assembly System.Windows.Forms
    $main_form = New-Object System.Windows.Forms.Form
    $main_form.Text ='GUI'
    $main_form.Width = 600
    $main_form.Height = 400
    $main_form.AutoSize = $true
    $Label = New-Object System.Windows.Forms.Label
    $Label.Text = "Utilisateurs AD"
    $Label.Location = New-Object System.Drawing.Point (0,10)
    $Label.AutoSize = $true
    $main_form.Controls.Add($Label)
    $ComboBox = New-Object System.Windows.Forms.ComboBox
     
    $ComboBox.Width = 300
     
    $Users = get-aduser -filter * -SearchBase "OU=xx,DC=xx,DC=lan"  -Properties SamAccountName
     
    Foreach ($User in $Users)
     
    {
     
    $ComboBox.Items.Add($User.Name + "|" + $User.SamAccountName );
     
    }
     
    $ComboBox.Location = New-Object System.Drawing.Point (90,10)
    $ComboBox.KeyUp = $prenom.Text='ok'
    $main_form.Controls.Add($ComboBox)
     
     
    $Label1 = New-Object System.Windows.Forms.Label
    $Label1.Text = "Nom"
    $Label1.Location = New-Object System.Drawing.Point (0,40)
    $Label1.AutoSize = $true
    $main_form.Controls.Add($Label1)
    $nom = New-Object System.Windows.Forms.TextBox
    $nom.Width = 300
    $nom.Location = New-Object System.Drawing.Point (90,40)
    $nom.CharacterCasing='Upper'
    $main_form.Controls.Add($nom)
     
     
    $Label2 = New-Object System.Windows.Forms.Label
    $Label2.Text = "Prenom"
    $Label2.Location = New-Object System.Drawing.Point (0,60)
    $Label2.AutoSize = $true
    $main_form.Controls.Add($Label2)
    $prenom = New-Object System.Windows.Forms.TextBox
    $prenom.Width = 300
    $prenom.Location = New-Object System.Drawing.Point (90,60)
    $main_form.Controls.Add($prenom)
     
     
    $Label4 = New-Object System.Windows.Forms.Label
    $Label4.Text = "login"
    $Label4.Location = New-Object System.Drawing.Point (0,80)
    $Label4.AutoSize = $true
    $main_form.Controls.Add($Label4)
    $login = New-Object System.Windows.Forms.TextBox
    $login.Width = 300
    $login.Location = New-Object System.Drawing.Point (90,80)
    $main_form.Controls.Add($login)
     
    $Label3 = New-Object System.Windows.Forms.Label
    $Label3.Text = "Email"
    $Label3.Location = New-Object System.Drawing.Point (0,100)
    $Label3.AutoSize = $true
    $main_form.Controls.Add($Label3)
    $email = New-Object System.Windows.Forms.TextBox
    $email.Width = 300
    $email.Location = New-Object System.Drawing.Point (90,100)
    $main_form.Controls.Add($email)
     
    $main_form.ShowDialog()


    Sur la zone Combox (liste déroulante), une fois l'utilisateur sélectionné, je voudrais récupérer les informations de AD et qu'il les inscrits dans les champs Prenom/nom (champs Textbox du script)
    Mais avant ça je voudrais déjà arriver une fois la sélection faite, inscrire un texte dans un des champs textbox du script.

    Est-ce réalisable? J'étais partie sur le KeyUp, mais je ne sais pas comment le formuler dans mon script

    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    ]$ComboBox.KeyUp = $prenom.Text='ok'

    Merci d'avance pour vos conseils

  2. #2
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 183
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 183
    Points : 5 754
    Points
    5 754
    Par défaut
    Bonjour,

    Tu devrais utiliser l'évènement SelectedIndexChanged

  3. #3
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 183
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 183
    Points : 5 754
    Points
    5 754
    Par défaut
    Voici une démonstration (j'ai inhibé la partie AD pour le moment)

    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
    #Import-Module ActiveDirectory
    Add-Type -assembly System.Windows.Forms
    $main_form = New-Object System.Windows.Forms.Form
    $main_form.Text ='GUI'
    $main_form.Width = 600
    $main_form.Height = 400
    $main_form.AutoSize = $true
    $Label = New-Object System.Windows.Forms.Label
    $Label.Text = "Utilisateurs AD"
    $Label.Location = New-Object System.Drawing.Point (0,10)
    $Label.AutoSize = $true
    $main_form.Controls.Add($Label)
    $ComboBox = New-Object System.Windows.Forms.ComboBox
    $ComboBox.Width = 300
    $ComboBox.Location = New-Object System.Drawing.Point (90,10)
     
    # $Users = get-aduser -filter * -SearchBase "OU=xx,DC=xx,DC=lan"  -Properties SamAccountName
     
    $Users = @()
    $Users += [PSCustomObject]@{
        Name     = 'Eric'
        SamAccountName = '123'
    }
    $Users += [PSCustomObject]@{
        Name     = 'toto'
        SamAccountName = '456'
    }
    Foreach ($User in $Users)
    {
        $ComboBox.Items.Add($User.Name + "|" + $User.SamAccountName);
    }
     
     
    $Label1 = New-Object System.Windows.Forms.Label
    $Label1.Text = "Nom"
    $Label1.Location = New-Object System.Drawing.Point (0,40)
    $Label1.AutoSize = $true
    $main_form.Controls.Add($Label1)
    $nom = New-Object System.Windows.Forms.TextBox
    $nom.Width = 300
    $nom.Location = New-Object System.Drawing.Point (90,40)
    $nom.CharacterCasing='Upper'
    $main_form.Controls.Add($nom)
     
     
    $Label2 = New-Object System.Windows.Forms.Label
    $Label2.Text = "Prenom"
    $Label2.Location = New-Object System.Drawing.Point (0,60)
    $Label2.AutoSize = $true
    $main_form.Controls.Add($Label2)
    $prenom = New-Object System.Windows.Forms.TextBox
    $prenom.Width = 300
    $prenom.Location = New-Object System.Drawing.Point (90,60)
    $main_form.Controls.Add($prenom)
     
     
    $Label4 = New-Object System.Windows.Forms.Label
    $Label4.Text = "login"
    $Label4.Location = New-Object System.Drawing.Point (0,80)
    $Label4.AutoSize = $true
    $main_form.Controls.Add($Label4)
    $login = New-Object System.Windows.Forms.TextBox
    $login.Width = 300
    $login.Location = New-Object System.Drawing.Point (90,80)
    $main_form.Controls.Add($login)
     
    $Label3 = New-Object System.Windows.Forms.Label
    $Label3.Text = "Email"
    $Label3.Location = New-Object System.Drawing.Point (0,100)
    $Label3.AutoSize = $true
    $main_form.Controls.Add($Label3)
    $email = New-Object System.Windows.Forms.TextBox
    $email.Width = 300
    $email.Location = New-Object System.Drawing.Point (90,100)
    $main_form.Controls.Add($email)
     
    $main_form.Controls.Add($ComboBox)
     
    $ComboBox.Add_SelectedIndexChanged({
        $nom.Text = $this.SelectedItem.ToString()
    })
     
    $main_form.ShowDialog()

    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    ...
    $ComboBox.Add_SelectedIndexChanged({
        $nom.Text = $this.SelectedItem.ToString()
    })
    ...

    PS : Si tu as beaucoup d'utilisateur préfère la méthode AddRange plus performante pour le peuplement en masse

  4. #4
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 183
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 183
    Points : 5 754
    Points
    5 754
    Par défaut
    Tu peux aussi utiliser la propriété DisplayMember du ComboBox (hérité de ListControl)

    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
    #Import-Module ActiveDirectory
    Add-Type -assembly System.Windows.Forms
    $main_form = New-Object System.Windows.Forms.Form
    $main_form.Text ='GUI'
    $main_form.Width = 600
    $main_form.Height = 400
    $main_form.AutoSize = $true
    $Label = New-Object System.Windows.Forms.Label
    $Label.Text = "Utilisateurs AD"
    $Label.Location = New-Object System.Drawing.Point (0,10)
    $Label.AutoSize = $true
    $main_form.Controls.Add($Label)
    $ComboBox = New-Object System.Windows.Forms.ComboBox
    $ComboBox.Width = 300
    $ComboBox.Location = New-Object System.Drawing.Point (90,10)
    $ComboBox.DisplayMember = "Name"
    # $Users = get-aduser -filter * -SearchBase "OU=xx,DC=xx,DC=lan"  -Properties SamAccountName
     
    $Users = @()
    $Users += [PSCustomObject]@{
        Name     = 'Eric'
        SamAccountName = '123'
    }
    $Users += [PSCustomObject]@{
        Name     = 'toto'
        SamAccountName = '456'
    }
    Foreach ($User in $Users)
    {
        $ComboBox.Items.Add($User);
    }
     
     
    $Label1 = New-Object System.Windows.Forms.Label
    $Label1.Text = "Nom"
    $Label1.Location = New-Object System.Drawing.Point (0,40)
    $Label1.AutoSize = $true
    $main_form.Controls.Add($Label1)
    $nom = New-Object System.Windows.Forms.TextBox
    $nom.Width = 300
    $nom.Location = New-Object System.Drawing.Point (90,40)
    $nom.CharacterCasing='Upper'
    $main_form.Controls.Add($nom)
     
     
    $Label2 = New-Object System.Windows.Forms.Label
    $Label2.Text = "Prenom"
    $Label2.Location = New-Object System.Drawing.Point (0,60)
    $Label2.AutoSize = $true
    $main_form.Controls.Add($Label2)
    $prenom = New-Object System.Windows.Forms.TextBox
    $prenom.Width = 300
    $prenom.Location = New-Object System.Drawing.Point (90,60)
    $main_form.Controls.Add($prenom)
     
     
    $Label4 = New-Object System.Windows.Forms.Label
    $Label4.Text = "login"
    $Label4.Location = New-Object System.Drawing.Point (0,80)
    $Label4.AutoSize = $true
    $main_form.Controls.Add($Label4)
    $login = New-Object System.Windows.Forms.TextBox
    $login.Width = 300
    $login.Location = New-Object System.Drawing.Point (90,80)
    $main_form.Controls.Add($login)
     
    $Label3 = New-Object System.Windows.Forms.Label
    $Label3.Text = "Email"
    $Label3.Location = New-Object System.Drawing.Point (0,100)
    $Label3.AutoSize = $true
    $main_form.Controls.Add($Label3)
    $email = New-Object System.Windows.Forms.TextBox
    $email.Width = 300
    $email.Location = New-Object System.Drawing.Point (90,100)
    $main_form.Controls.Add($email)
     
    $main_form.Controls.Add($ComboBox)
     
    $ComboBox.Add_SelectedIndexChanged({
        $nom.Text = $this.SelectedItem.SamAccountName.ToString()
    })
     
    $main_form.ShowDialog()

    Voir aussi ValueMember

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    816
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 816
    Points : 49
    Points
    49
    Par défaut
    Bonsoir à tous,

    merci pour votre aide votre exemple à pu m'aider

    j'ai avancé sur mon script qui fonctionne, sauf sur une ligne qui m'indiquer syntaxe incorrect:

    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
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
     
    Import-Module ActiveDirectory
    Add-Type -assembly System.Windows.Forms
    $main_form = New-Object System.Windows.Forms.Form
    $main_form.Text ='GUI'
    $main_form.Width = 600
    $main_form.Height = 400
    $main_form.AutoSize = $true
    $Label = New-Object System.Windows.Forms.Label
    $Label.Text = "Utilisateurs AD"
    $Label.Location = New-Object System.Drawing.Point (0,10)
    $Label.AutoSize = $true
    $main_form.Controls.Add($Label)
    $ComboBox = New-Object System.Windows.Forms.ComboBox
     
    $ComboBox.Width = 300
     
    $Users = get-aduser -filter * -SearchBase "OU=xx,DC=xx,DC=lan"  -Properties SamAccountName, Name, sn,givenName | Sort-Object sn
     
    #$Users = get-aduser -Filter { SamAccountName -eq "ncottez"} 
     
    Foreach ($User in $Users)
     
    {
     
    $ComboBox.Items.Add($User.sn + $User.givenName + " | " + $User.SamAccountName );
     
    }
     
    $ComboBox.Location = New-Object System.Drawing.Point (90,10)
     
    $main_form.Controls.Add($ComboBox)
     
     
     
     
     
    $Label2 = New-Object System.Windows.Forms.Label
    $Label2.Text = "Prenom"
    $Label2.Location = New-Object System.Drawing.Point (0,40)
    $Label2.AutoSize = $true
    $main_form.Controls.Add($Label2)
    $prenom = New-Object System.Windows.Forms.TextBox
    $prenom.Width = 300
    $prenom.Location = New-Object System.Drawing.Point (90,40)
    $main_form.Controls.Add($prenom)
     
     
    $Label1 = New-Object System.Windows.Forms.Label
    $Label1.Text = "Nom"
    $Label1.Location = New-Object System.Drawing.Point (0,60)
    $Label1.AutoSize = $true
    $main_form.Controls.Add($Label1)
    $nom = New-Object System.Windows.Forms.TextBox
    $nom.Width = 300
    $nom.Location = New-Object System.Drawing.Point (90,60)
    $nom.CharacterCasing='Upper'
    $main_form.Controls.Add($nom)
     
    $Label10 = New-Object System.Windows.Forms.Label
    $Label10.Text = "Nom Affichage"
    $Label10.Location = New-Object System.Drawing.Point (0,80)
    $Label10.AutoSize = $true
    $main_form.Controls.Add($Label10)
    $nomaffichage = New-Object System.Windows.Forms.TextBox
    $nomaffichage.Width = 300
    $nomaffichage.Location = New-Object System.Drawing.Point (90,80)
     
    $main_form.Controls.Add($nomaffichage)
     
    $Label4 = New-Object System.Windows.Forms.Label
    $Label4.Text = "login"
    $Label4.Location = New-Object System.Drawing.Point (0,100)
    $Label4.AutoSize = $true
    $main_form.Controls.Add($Label4)
    $login = New-Object System.Windows.Forms.TextBox
    $login.Width = 300
    $login.Location = New-Object System.Drawing.Point (90,100)
    $main_form.Controls.Add($login)
     
    $Label3 = New-Object System.Windows.Forms.Label
    $Label3.Text = "Email"
    $Label3.Location = New-Object System.Drawing.Point (0,120)
    $Label3.AutoSize = $true
    $main_form.Controls.Add($Label3)
    $email = New-Object System.Windows.Forms.TextBox
    $email.Width = 300
    $email.Location = New-Object System.Drawing.Point (90,120)
    $main_form.Controls.Add($email)
     
     
    $Label5 = New-Object System.Windows.Forms.Label
    $Label5.Text = "Description"
    $Label5.Location = New-Object System.Drawing.Point (0,140)
    $Label5.AutoSize = $true
    $main_form.Controls.Add($Label5)
    $description = New-Object System.Windows.Forms.TextBox
    $description.Width = 100
    $description.Location = New-Object System.Drawing.Point (90,140)
    $main_form.Controls.Add($description)
     
    $Label51 = New-Object System.Windows.Forms.Label
    $Label51.Text = "Service"
    $Label51.Location = New-Object System.Drawing.Point (250,140)
    $Label51.AutoSize = $true
    $main_form.Controls.Add($Label51)
    $service = New-Object System.Windows.Forms.TextBox
    $service.Width = 100
    $service.Location = New-Object System.Drawing.Point (300,140)
    $main_form.Controls.Add($service)
     
    $Label52 = New-Object System.Windows.Forms.Label
    $Label52.Text = "Societe"
    $Label52.Location = New-Object System.Drawing.Point (400,140)
    $Label52.AutoSize = $true
    $main_form.Controls.Add($Label52)
    $societe = New-Object System.Windows.Forms.TextBox
    $societe.Width = 100
    $societe.Location = New-Object System.Drawing.Point (450,140)
    $main_form.Controls.Add($societe)
     
    $Label6 = New-Object System.Windows.Forms.Label
    $Label6.Text = "tel"
    $Label6.Location = New-Object System.Drawing.Point (0,160)
    $Label6.AutoSize = $true
    $main_form.Controls.Add($Label6)
    $tel = New-Object System.Windows.Forms.TextBox
    $tel.Width = 300
    $tel.Location = New-Object System.Drawing.Point (90,160)
    $main_form.Controls.Add($tel)
     
    $Label7 = New-Object System.Windows.Forms.Label
    $Label7.Text = "Mobile"
    $Label7.Location = New-Object System.Drawing.Point (0,180)
    $Label7.AutoSize = $true
    $main_form.Controls.Add($Label7)
    $mobile = New-Object System.Windows.Forms.TextBox
    $mobile.Width = 300
    $mobile.Location = New-Object System.Drawing.Point (90,180)
    $main_form.Controls.Add($mobile)
     
    $Label8 = New-Object System.Windows.Forms.Label
    $Label8.Text = "Ipphone"
    $Label8.Location = New-Object System.Drawing.Point (0,200)
    $Label8.AutoSize = $true
    $main_form.Controls.Add($Label8)
    $ipphone = New-Object System.Windows.Forms.TextBox
    $ipphone.Width = 300
    $ipphone.Location = New-Object System.Drawing.Point (90,200)
    $main_form.Controls.Add($ipphone)
     
    $Label9 = New-Object System.Windows.Forms.Label
    $Label9.Text = "MOtDePasse"
    $Label9.Location = New-Object System.Drawing.Point (0,220)
    $Label9.AutoSize = $true
    $main_form.Controls.Add($Label9)
    $mdp = New-Object System.Windows.Forms.TextBox
    $mdp.Width = 300
    $mdp.text = "***********"
    $mdp.Location = New-Object System.Drawing.Point (90,220)
    $main_form.Controls.Add($mdp)
     
    $Label91 = New-Object System.Windows.Forms.Label
    $Label91.Text = "OU"
    $Label91.Location = New-Object System.Drawing.Point (0,220)
    $Label91.AutoSize = $true
    $main_form.Controls.Add($Label91)
    $ou = New-Object System.Windows.Forms.TextBox
    $ou.Width = 300
    $ou.text = ""
    $ou.Location = New-Object System.Drawing.Point (90,240)
    $main_form.Controls.Add($ou)
     
        # create your checkbox 
        $Label10 = New-Object System.Windows.Forms.Label
    $Label10.Text = "ForceChangeMdp"
    $Label10.Location = New-Object System.Drawing.Point (0,260)
    $Label10.AutoSize = $true
    $main_form.Controls.Add($Label10)
     
        $changemdp = new-object System.Windows.Forms.checkbox
        $changemdp.Location = new-object System.Drawing.Size(110,260)
       # $changemdp.Size = new-object System.Drawing.Size(0,260)
       # $changemdp.Text = "Forcer Changer Mdp"
        $changemdp.Checked = $true
        $main_form.Controls.Add($changemdp) 
     
     
     
            # Add an OK button
        $OKButton = new-object System.Windows.Forms.Button
        $OKButton.Location = new-object System.Drawing.Size(0,280)
        $OKButton.Size = new-object System.Drawing.Size(100,40)
        $OKButton.Text = "creation"
        #$OKButton.Add_Click({$Form.Close()})
        $main_form.Controls.Add($OKButton)
     
    $main_form.Controls.Add($ComboBox)
     
    $ComboBox.Add_SelectedIndexChanged({
        $loginsplit = $this.SelectedItem.ToString().Split("|")
        $loginsplit.GetType()
        # Write-Host $loginsplit[0]
        #$nom.Text =$loginsplit[1].Trim()
        $temp =$loginsplit[1]
        Write-Host $temp
        $Users2 = get-aduser -Filter  "SamAccountName -eq '$temp'"  -properties description, iPphone,telephoneNumber, mobile, company, department, DistinguishedName
        #$prenom.Text = $Users2.SamAccountName
        $description.Text = $Users2.description
        $mobile.Text = $Users2.mobile
        $tel.Text = $Users2.telephoneNumber
        $ipphone.Text = $Users2.ipphone
        $service.Text = $Users2.department
        $societe.Text = $Users2.company
        $ou.Text = $Users2.DistinguishedName.Split(',',2)[1]
        Write-Host $Users2.mail
     
    })
     
    $prenom.Add_KeyUp({
    Write-Host "kkkkkkkkkkk"
    $nomaffichage.Text= $prenom.text +' '+$nom.Text
     
    })
    $nom.Add_KeyUp({
    Write-Host "kkkkkkkkkkk"
    $nomaffichage.Text= $prenom.text +' '+$nom.Text
     
    })
     
    $login.Add_TextChanged({
    Write-Host "nnnn"
    if (!(Get-ADUser -Filter "sAMAccountName -eq '$($login.Text)'")) {
        Write-Host "User does not exist."
        $email.Text= $login.text + "@xxxxxxxxxxxxxxx.com"
         $OKButton.Enabled = $true
    }
    else
    {
     
    Write-Host "User  exist!!."
     $OKButton.Enabled = $false
    }
     
    })
     
     
    #######################################################
        $OKButton.Add_Click({
            $loginsplit = $ComboBox.SelectedItem.ToString().Split("|")
        $loginsplit.GetType()
        # Write-Host $loginsplit[0]
        #$nom.Text =$loginsplit[1].Trim()
        $temp =$loginsplit[1]
        Write-Host $temp
       # [System.Windows.Forms.MessageBox]::Show("Hello World." , "My Dialog Box" + $temp)
       $userInstance = Get-ADUser -Identity $temp
      New-ADUser `
        -SAMAccountName $login.text `
        -Instance $userInstance `
        -Surname $nom.Text `
        -givenName $prenom.Text `
        -DisplayName $nomaffichage.Text `
        -Name $nomaffichage.Text `
        -UserPrincipalName $email.Text `
        -OfficePhone $tel.Text `
        -mobile $mob.Text  `
        -EmailAddress $email.Text `
        -description $description.text `
        -title $description.text `
        -company $societe.Text `
        -Department $service.Text `
        -Enabled $True  `
        -AccountPassword (convertto-securestring $mdp -AsPlainText -Force) `
        -ChangePasswordAtLogon $true `
        -Path $ou
     
      Set-ADUser -Identity $login.text -add @{ipPhone = $ipphone.Text}
      Get-ADUser -Identity $temp -Properties memberof | Select-Object -ExpandProperty memberof | Add-ADGroupMember -Members $login.text
      #-ipPhone $ipphone.Text
        })
     
    $main_form.ShowDialog()

    c'est cette partie du code (création d'un utilisateur dans AD)

    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
     
      New-ADUser `
        -SAMAccountName $login.text`
        -Instance $userInstance`
        -Surname $nom.Text`
        -givenName $prenom.Text`
        -DisplayName $nomaffichage.Text`
        -Name $nomaffichage.Text`
        -UserPrincipalName $email.Text`
        -OfficePhone $tel.Text`
        -mobile $mob.Text`
        -EmailAddress $email.Text`
        -description $description.text`
        -title $description.text`
        -company $societe.Text`
        -Department $service.Text`
        -Enabled $True`
        -AccountPassword (convertto-securestring $mdp -AsPlainText -Force)`
        -ChangePasswordAtLogon $true`
        -Path $ou

    je vois pas dans ma ligne d'erreur? J'indiqué les paremetre de "new-aduser" en dessous pour plus de visibilité avec ` comme caractere

    ou est-je commis mon erreur?

    guigui69

  6. #6
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 183
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 183
    Points : 5 754
    Points
    5 754
    Par défaut
    Oui c'est permis, la création n'a pas l'air d'avoir d'erreur à première vu, par contre il faudrait vérifier les variables car je ne comprends pas trop ceci
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
            $loginsplit = $ComboBox.SelectedItem.ToString().Split("|")
        $loginsplit.GetType()
        # Write-Host $loginsplit[0]
        #$nom.Text =$loginsplit[1].Trim()
        $temp =$loginsplit[1]
        Write-Host $temp
       # [System.Windows.Forms.MessageBox]::Show("Hello World." , "My Dialog Box" + $temp)
       $userInstance = Get-ADUser -Identity $temp

    D’ailleurs je ne connais pas le but du script non plus.

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    816
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 816
    Points : 49
    Points
    49
    Par défaut
    Bonjour,

    mon script va permet de copier les paramètres d'un utilisateur pour "copier" sur un nouveau utilisateur.
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     $userInstance = Get-ADUser -Identity $temp

    Mon script généré une liste déroulante des utilisateurs existant dans AD et avec ce code je recupere le compte utilisateur en question
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
      $loginsplit = $ComboBox.SelectedItem.ToString().Split("|")
        $loginsplit.GetType()
            $temp =$loginsplit[1]

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    816
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 816
    Points : 49
    Points
    49
    Par défaut
    Bonjour,

    j'ai corrigé mon problème (en rajoutant
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    -Path $ou.Text  au lieu de -Path $ou
    )



    je continue dans mon script ou j'interroge une base mySQL et je cherche à faire un insert:

    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
     
    $query="INSERT INTO ``users`` (id_users,login,nom,prenom,mail,tel,fax,service,societe,users_disabled,bc_application,bc_realiser,bc_valider,
    bc_rechercher,bc_del,f_application,f_realiser,f_rechercher,rh_application,rh_realiser,rh_visualiser,rh_conges,date,
    rh_stage,rh_entretien_annuel,com_application,com_add,com_stat,com_obj,com_volume,com_boursevo,com_add_challenge,com_add_obj_challenge,com_mod_obj_challenge,
    com_visu_challenge,com_fin_add,com_fin_payplan,com_fin,suivi_application,suivi_creer,suivi_budget,suivi_client,suivi_client_compta,admin_application) SELECT '', 
    '$login.text', 
    '$nom', 
    '$prenom',
    '$email',
    '$tel.Text ', 
    '',
    '$societe',
    '$service',
    '0',
    bc_application,bc_realiser,bc_valider,
    bc_rechercher,bc_del,f_application,f_realiser,f_rechercher,rh_application,rh_realiser,rh_visualiser,rh_conges,STR_TO_DATE(now(),'%d/%m/%Y'),
    rh_stage,rh_entretien_annuel,com_application,com_add,com_stat,com_obj,com_volume,com_boursevo,com_add_challenge,com_add_obj_challenge,com_mod_obj_challenge,
    com_visu_challenge,com_fin_add,com_fin_payplan,com_fin,suivi_application,suivi_creer,suivi_budget,suivi_client,suivi_client_compta,admin_application FROM users WHERE login='$temp'"

    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    '$login.text', 
    '$nom', 
     
    résultat:
    'System.Windows.Forms.TextBox, Text:bob ', 
    'System.Windows.Forms.TextBox, Text:eponge ',
    et dans ma table mysql c'est enregistrer avec ceci 'System.Windows.Forms.TextBox, Text +ma donnée' a chaque fois alors que la variable $temp est bien interprété.

    pourquoi? Qu'est que j'ai oublié dans mon code pour qu'il insere uniquement la donnée?

    guigui69

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    816
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 816
    Points : 49
    Points
    49
    Par défaut
    je me repond à moi meme, il fallait ajouter comme ceci
    Code powerhsell : Sélectionner tout - Visualiser dans une fenêtre à part
    $($login.text)

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    816
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 816
    Points : 49
    Points
    49
    Par défaut
    Bonjour,

    j'avance sur mon script powershell je bloque tu deux points:
    1.voici interface graphique du script
    Nom : 021-12-04 122431.png
Affichages : 421
Taille : 12,2 Ko

    Dans mon script j'ai ajouter ci-dessous au moment du clic sur le bouton création: un check qui regarde si le champs ipphone est renseigné, mais cela fonctionne pas , car quand le champs est vide pour lui la condition est OK et donc essai enregistrer le champs
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     if ($ipphone.Text -ne '' -or $ipphone.Text -ne $null)
       {
     
       Set-ADUser -Identity $login.text -add @{ipPhone = $ipphone.Text}
       }

    quelle erreur est-je commis dans ce code

    2. Dans le script il y a une partie pour réaliser les "créations" sur la partie office365 (Affectation licence; Mise en FR; etc..)

    Dans mon script je lance la synchro ADlocal/ Azure (
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    Start-ADSyncSyncCycle -PolicyType Delta
    ) ,il y a délai pour que cela remonte dans notre office365.

    je cherche a mettre/ a dire dans le script "tant que l'utilisateur n'apparait pas dans office365 tu attends avant exécuter la suite du script." Comment je pourrais faire pour interpreter cela en powershell?

    merci d'avance pour vos conseils

    guigui69

  11. #11
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 183
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 183
    Points : 5 754
    Points
    5 754
    Par défaut
    1) Ta condition sera toujours vrai car soit le champ sera vide soit il sera égale à nulle.
    Vu que tu rentre dans le bloc si l'un OU l'autre est vrai
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    ($ipphone.Text -ne '' -and $ipphone.Text -ne $null)

    Tu peux utiliser la méthode statique IsNullOrEmpty de la classe string pour plus d'efficacité/lisibilité
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    (![string]::IsNullOrEmpty($ipphone.Text))

    2) Je n'ai jamais joué avec les cmdlet Azure, désolé.
    Sinon si tu as une commande pour vérifier sa présence, il suffirait de boucler pendant un certain temps.

  12. #12
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    816
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 816
    Points : 49
    Points
    49
    Par défaut
    Bonjour à tous,

    je reviens sur mon sujet mon script fonctionne mais a la fin de l’exécution j'ai ce message

    Pièce jointe 624652

    c'est pas bloquant , car mon script GUI fonctionne mais je voudrais corriger cette erreur, mais je n'ai pas indication sur la ligne qui génère cette erreur.

    Nom : Capturescpower2.PNG
Affichages : 315
Taille : 13,7 Ko

    Comment je pourrais avoir une piste indication sur la partie du code qu'il lui pose un probleme?

    merci davance de vos conseils

    guigui69

  13. #13
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 183
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 183
    Points : 5 754
    Points
    5 754
    Par défaut
    Bonjour,
    Je ne vois pas de message d'erreur

  14. #14
    Futur Membre du Club
    Homme Profil pro
    sans
    Inscrit en
    Mars 2019
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Tarn (Midi Pyrénées)

    Informations professionnelles :
    Activité : sans

    Informations forums :
    Inscription : Mars 2019
    Messages : 13
    Points : 7
    Points
    7
    Par défaut
    bonjour,

    j'ai testé votre script qui est très sympa.

    par contre savez-vous pourquoi la recherche via le login ne fonctionne pas ?
    uniquement la recherche de l'utilisateur via le nom fonctionne.

  15. #15
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    816
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 816
    Points : 49
    Points
    49
    Par défaut
    Bonsoir,

    je pense avoir trouvé erreur

    Par contre maintenant avec office365 le MFA est activé et cherche la méthode en powerhsell qui remplace la fenêtre (petite authentification de base )par authentification moderne et MFA

Discussions similaires

  1. Sap gui scripting - ABAP - scripting windows
    Par Filou78C dans le forum SAP
    Réponses: 0
    Dernier message: 17/06/2015, 17h07
  2. [Débutant] Créer un GUI qui fait intervenir des scripts avec des inputs
    Par segolavie dans le forum Interfaces Graphiques
    Réponses: 5
    Dernier message: 30/07/2012, 02h13
  3. Composant COM pour ajouter une GUI à un script
    Par omen999 dans le forum Vos Contributions VBScript
    Réponses: 3
    Dernier message: 14/02/2008, 00h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo