Dynamic End-User Menu

This topic contains 1 reply, has 2 voices, and was last updated by  Pradeep Arora 1 week, 6 days ago.

  • Author
    Posts
  • #83734

    Juan
    Participant

    Hi Folks-

    Im building a tool for my Help Desk team to assist in the creation of Distribution Groups in AD. I want the script to be as "user-friendly" and re-usable as possible – only requiring the end-user to enter the name of the group and the associated OU for nesting.

    In situations where there are multiple OUs with the same name, I'd like to present the enduser with a dynamic interactive menu to select the correct option – dynamic in that the options presented depend on the amount of OUs with the same name in our environment.

    I was thinking to build a hash table of the available options but am having trouble converting the table into an interactive menu (from lack of experience). I've located resources that show how to accomplish this task with static menus but none for dynamic. Below is a snippet of what i have so far and would appreciate any guidance or perhaps recommendations on an alternate solution.

    ..........
        $OU = Read-Host "Enter the Name of the Organizational Unit where the group will reside. Ex.'Accounting'"
        $OptionsObj = @{}
        $i = 0
        $OUSearch = Get-ADOrganizationalUnit -Filter {Name -eq $OU}  | Select -ExpandProperty DistinguishedName
    
        While($OUSearch -eq $null)
            {
                Write-Warning "Unable to locate OU"
                $OU = Read-Host "Enter the Name of the Organizational Unit where the group will reside. Ex.'Accounting'"
                $OUSearch = Get-ADOrganizationalUnit -Filter {Name -eq $OU}  | Select -ExpandProperty DistinguishedName
            }
    
        If($OUsearch.count -gt 1)
            {
                Foreach($OUnit in $OUSearch)
                    {
                        $i++
                        $OptionsObj.Add("$i","$OUnit")         
                    }
    	    Write-Verbose "Multiple OU's Found with the Same Name:" -Verbose
                
                #Displays Hash Table of OUs with the same name
                $OptionsObj.GetEnumerator()|Sort -Property Name
    	}
       Else
    	{
                $OU = $OUSearch
            }
       ...................
    

    Thanks!

  • #83740

    Pradeep Arora
    Participant

    I extracted code, this might help you out: This will create a list of 3 to pick from, multiple allowed.

    $all=@("A. item A", "B. item B", "C. item C")
    do {
    $xx = $all | 
    Out-GridView -PassThru  -Title 'MAIN MENU'
    if ($xx.Length -gt 0) {
    	try {
    		$xx2 = write-host $xx
    	}
    	catch{}
    	$xx3 = ($xx2 | Out-GridView -PassThru)
    	if (($xx3 | Measure-Object).Count -gt 0){	#we get @() or single object or none
    	#$xx3 | Get-Member
    	#Write-Host "Length=" $xx3.Length
    	$xx3 | Select-Object -Property *
    	}
    }
    } until ($xx.Length -eq 0)
    

You must be logged in to reply to this topic.