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 :

Récupération des OU de l'Active Directory dans une liste déroulante


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Février 2023
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suède

    Informations professionnelles :
    Activité : Responsable de service informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2023
    Messages : 1
    Par défaut Récupération des OU de l'Active Directory dans une liste déroulante
    Bonjour,

    J'ai une fonction qui récupère les OU ds une liste déroulante. Je n'arrive pas à allouer le L'OU choisie dans la liste à une variable.

    Code : 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
    
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    
    
    
    function Choose-ADOrganizationalUnit {
      [CmdletBinding()]
      param (
        [string]$Title = "Choisir une unité d'organisation"
      )
    
      # Récupération de toutes les OUs de l'Active Directory
      $Ous = Get-ADOrganizationalUnit -Filter *
    
      # Création de la fenêtre
      $Form = New-Object System.Windows.Forms.Form
      $Form.Text = $Title
      $Form.Size = New-Object System.Drawing.Size(500,200)
      $Form.StartPosition = "CenterScreen"
    
      # Création de la liste déroulante
      $ComboBox = New-Object System.Windows.Forms.ComboBox
      $ComboBox.Size = New-Object System.Drawing.Size(360,20)
      $ComboBox.Location = New-Object System.Drawing.Point(50,50)
    
      # Ajout des OUs à la liste déroulante
      foreach ($Ou in $Ous) {
        $ComboBox.Items.Add($Ou.DistinguishedName)
      }
    
      $Form.Controls.Add($ComboBox)
    
      # Création du bouton OK
      $OKButton = New-Object System.Windows.Forms.Button
      $OKButton.Text = "OK"
      $OKButton.Size = New-Object System.Drawing.Size(75,23)
      $OKButton.Location = New-Object System.Drawing.Point(200,100)
      $OKButton.Add_Click({
        # Récupération de la OU sélectionnée
        
        $SelectedOu = $ComboBox.SelectedItem
        
        # Fermeture de la fenêtre
        $Form.Close()
      })
      $Form.Controls.Add($OKButton)
      
      
      write-host $SelectedOu
      # Affichage de la fenêtre
      $Form.ShowDialog() | Out-Null
    
      # Retour de la OU sélectionnée
      return $SelectedOu2
    }
    
    $result = Choose-ADOrganizationalUnit
    
    write-host $result

  2. #2
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 218
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    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 218
    Par défaut
    Voici quelques approches, je préfère la solution 3

    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
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
     
     
    function Choose-ADOrganizationalUnit {
      [CmdletBinding()]
      param (
        [string]$Title = "Choisir une unité d'organisation"
      )
     
      # Récupération de toutes les OUs de l'Active Directory
      #$Ous = Get-ADOrganizationalUnit -Filter *
      $Ous = @("toto", "tata", "titi")
     
      # Création de la fenêtre
      $Form = New-Object System.Windows.Forms.Form
      $Form.Text = $Title
      $Form.Size = New-Object System.Drawing.Size(500,200)
      $Form.StartPosition = "CenterScreen"
     
      # Création de la liste déroulante
      $ComboBox = New-Object System.Windows.Forms.ComboBox
      $ComboBox.Size = New-Object System.Drawing.Size(360,20)
      $ComboBox.Location = New-Object System.Drawing.Point(50,50)
     
      # Ajout des OUs à la liste déroulante
      foreach ($Ou in $Ous) {
        [void]$ComboBox.Items.Add($Ou)
      }
     
      $Form.Controls.Add($ComboBox)
     
      # Création du bouton OK
      $OKButton = New-Object System.Windows.Forms.Button
      $OKButton.Text = "OK"
      $OKButton.Size = New-Object System.Drawing.Size(75,23)
      $OKButton.Location = New-Object System.Drawing.Point(200,100)
     
      $OKButton.Add_Click({
        # Récupération de la OU sélectionnée
        $Script:SelectedOu = $ComboBox.SelectedItem
     
        # Fermeture de la fenêtre
        $Form.Close()
      })
      $Form.Controls.Add($OKButton)
     
      # Affichage de la fenêtre
      $Form.ShowDialog() | Out-Null
     
      # Retour de la OU sélectionnée
      return $Script:SelectedOu
    }
     
    $result = Choose-ADOrganizationalUnit
     
    write-host $result

    ou

    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
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
     
     
    function Choose-ADOrganizationalUnit {
      [CmdletBinding()]
      param (
        [string]$Title = "Choisir une unité d'organisation"
      )
     
      # Récupération de toutes les OUs de l'Active Directory
      #$Ous = Get-ADOrganizationalUnit -Filter *
      $Ous = @("toto", "tata", "titi")
     
      # Création de la fenêtre
      $Form = New-Object System.Windows.Forms.Form
      $Form.Text = $Title
      $Form.Size = New-Object System.Drawing.Size(500,200)
      $Form.StartPosition = "CenterScreen"
     
      # Création de la liste déroulante
      $ComboBox = New-Object System.Windows.Forms.ComboBox
      $ComboBox.Size = New-Object System.Drawing.Size(360,20)
      $ComboBox.Location = New-Object System.Drawing.Point(50,50)
     
      # Ajout des OUs à la liste déroulante
      foreach ($Ou in $Ous) {
        [void]$ComboBox.Items.Add($Ou)
      }
     
      $Form.Controls.Add($ComboBox)
     
      # Création du bouton OK
      $OKButton = New-Object System.Windows.Forms.Button
      $OKButton.Text = "OK"
      $OKButton.Size = New-Object System.Drawing.Size(75,23)
      $OKButton.Location = New-Object System.Drawing.Point(200,100)
     
      $OKButton.Add_Click({
        # Fermeture de la fenêtre
        $Form.Close()
      })
      $Form.Controls.Add($OKButton)
     
      # Affichage de la fenêtre
      $Form.ShowDialog() | Out-Null
     
      # Retour de la OU sélectionnée
      return $ComboBox.SelectedItem
    }
     
    $result = Choose-ADOrganizationalUnit
     
    write-host $result

    ou

    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
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
     
    function Choose-ADOrganizationalUnit {
      [CmdletBinding()]
      param (
        [string]$Title = "Choisir une unité d'organisation"
      )
     
      # Récupération de toutes les OUs de l'Active Directory
      #$Ous = Get-ADOrganizationalUnit -Filter *
      $Ous = @("toto", "tata", "titi")
     
      # Création de la fenêtre
      $Form = New-Object System.Windows.Forms.Form
      $Form.Text = $Title
      $Form.Size = New-Object System.Drawing.Size(500,200)
      $Form.StartPosition = "CenterScreen"
     
      # Création de la liste déroulante
      $ComboBox = New-Object System.Windows.Forms.ComboBox
      $ComboBox.Size = New-Object System.Drawing.Size(360,20)
      $ComboBox.Location = New-Object System.Drawing.Point(50,50)
     
      # Ajout des OUs à la liste déroulante
      foreach ($Ou in $Ous) {
        [void]$ComboBox.Items.Add($Ou)
      }
     
      $Form.Controls.Add($ComboBox)
     
      # Création du bouton OK
      $OKButton = New-Object System.Windows.Forms.Button
      $OKButton.Text = "OK"
      $OKButton.Size = New-Object System.Drawing.Size(75,23)
      $OKButton.Location = New-Object System.Drawing.Point(200,100)
      $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
     
      $Form.Controls.Add($OKButton)
     
      # Affichage de la fenêtre
      if ($Form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and $ComboBox.SelectedItem)
      {
        return $ComboBox.SelectedItem
      }
    }
     
    $result = Choose-ADOrganizationalUnit
     
    write-host $result

Discussions similaires

  1. Active Directory dans une base de données
    Par nrike2006 dans le forum Requêtes
    Réponses: 0
    Dernier message: 15/08/2018, 01h50
  2. Réponses: 1
    Dernier message: 09/12/2014, 13h57
  3. erreur récupération des données depuis base de données dans une liste
    Par amintoraa dans le forum Développement Web en Java
    Réponses: 3
    Dernier message: 25/04/2014, 23h41
  4. Réponses: 2
    Dernier message: 22/02/2012, 01h03
  5. Réponses: 20
    Dernier message: 04/01/2008, 11h08

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