peterz
Goto Top

AD-Gruppen Auswahl als Dropdownliste

Hallo,

ich möchte mir u.a. die Mitgliedschaft von AD-Gruppen mittels Powershell anzeigen lassen.
Das ganze mach ich so:
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null  
$Gruppenname = [Microsoft.VisualBasic.Interaction]::InputBox('Nach welcher Gruppe soll gesucht werden?', 'Mitglieder suchen', "Gruppenname")  

    If (Get-ADGroup -Filter {samAccountname -eq $Gruppenname}) 
    {
    Get-ADGroupmember -identity $Gruppenname | select Name | Out-Gridview   
    }
    Else
    {
     [System.Windows.Forms.MessageBox]::Show("Gruppe nicht vorhanden.","Abbruch",0,  [System.Windows.Forms.MessageBoxIcon]::Error)   
    Exit
    }

Bei diesem Code muss ich die Gruppennamen in die Inputbox schreiben.
Schön wäre es, wenn ich alle Gruppen in einem Listenfeld zur Auswahl angezeigt bekommen würde (anstatt der Inputbox) und ich mit der Maus die Gruppe zur weiteren Bearbeitung auswählen könnte.
Ist das möglich?
Wenn ja, wie?

Content-ID: 340518

Url: https://administrator.de/forum/ad-gruppen-auswahl-als-dropdownliste-340518.html

Ausgedruckt am: 11.04.2025 um 07:04 Uhr

133417
133417 13.06.2017 um 14:18:17 Uhr
Goto Top
Selbes Schema wie hier
Powershell Gui drop downfeld mit usernamen
Einfach nur durch die Gruppenauslese ersetzen.

Gruß
133417
133417 13.06.2017 aktualisiert um 14:33:53 Uhr
Goto Top
function GenerateForm {

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null  
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null  
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$comboGroups = New-Object System.Windows.Forms.ComboBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

$handler_comboBox1_SelectedIndexChanged= 
{
    $members = Get-ADGroupmember -identity $comboGroups.SelectedItem -Recursive
    if ($members){
        $members | select @{n='Mitglieder';e={$_.Name}} | ogv  
    }else{
        [System.Windows.Forms.MessageBox]::Show("Gruppe hat keine Mitglieder","Info",0,64)  
    }
    
}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 49
$System_Drawing_Size.Width = 201
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.FormBorderStyle = 3
$form1.MaximizeBox = $False
$form1.MinimizeBox = $False
$form1.Name = "form1"  
$form1.SizeGripStyle = 2
$form1.Text = "Choose Group"  

$comboGroups.Anchor = 13
$comboGroups.DataBindings.DefaultDataSourceUpdateMode = 0
$comboGroups.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 12
$comboGroups.Location = $System_Drawing_Point
$comboGroups.Name = "comboGroups"  
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 21
$System_Drawing_Size.Width = 177
$comboGroups.Size = $System_Drawing_Size
$comboGroups.TabIndex = 0
$comboGroups.add_SelectedIndexChanged($handler_comboBox1_SelectedIndexChanged)
$comboGroups.Items.AddRange((Get-ADGroup -Filter * | select -Expand Name))

$form1.Controls.Add($comboGroups)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function
GenerateForm
Peterz
Peterz 13.06.2017 um 15:11:55 Uhr
Goto Top
Das ist ja cool.
Vielen Dank.
133417
133417 13.06.2017 um 17:53:19 Uhr
Goto Top
Na dann, Haken nicht vergessen.