PoshCode Archive  Artifact Content

Artifact c772de5a4c68ce979621d1088a681489cb585d07d243e3fd6a17976761cc19c7:

  • File Select-UserGroup.ps1 — part of check-in [e7bd27003a] at 2018-06-10 13:15:06 on branch trunk — A script for ShowUI 1.0 — using Quest’s active directory cmdlets to retrieve user information and allow you to select one of the groups they’re a member of. Could be extended to populate a bunch of form fields from active directory and even allow updating them… (user: Joel Bennett size: 1496)

# encoding: ascii
# api: powershell
# title: Select-UserGroup
# description: A script for ShowUI 1.0 — using Quest’s active directory cmdlets to retrieve user information and allow you to select one of the groups they’re a member of.  Could be extended to populate a bunch of form fields from active directory and even allow updating them…
# version: 0.1
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 2737
# x-archived: 2012-01-03T12:18:12
# x-published: 2012-06-17T20:07:00
#
#
New-Grid -ControlName SelectUserGroups -Columns Auto,* -Rows 4 {
    $GetGroups = { 
        $user = Get-QADUuser $this.Text -SizeLimit 1
        if($User.LogonName -eq $this.Text -or $User.Email -eq $this.Text) {
            $this.Foreground = "Black" 
            $Group.ItemsSource = Get-QADGroup -ContainsMember $user
            $UserName.Text = $user.LogonName
            $EmailAddress.Text = $user.Email
        } else {
            $this.Foreground = "Red" 
            $Group.ItemsSource = @()         
        }
    }
    
    New-Label "Name"
    New-Textbox -name UserName -minwidth 100 -Column 1 -On_LostFocus $GetGroups
    
    New-Label "Email" -Row 1
    New-Textbox -name EmailAddress -minwidth 100  -Column 1 -Row 1  -On_LostFocus $GetGroups
    
    New-Label "Group" -Row 2
    New-Listbox -name Group -Column 1 -Row 2
    
    New-Button "OK" -Row 3 -Column 1 -On_Click { Get-ParentControl | Set-UIValue -Passthru | Close-Control }
} -Show