Carl Billington
asked on
Powershell: Input variable prompting a user to select an Organisational Unit from a list
I am writing a powershell script and one of the input variables that I would like to include is for the user to select an OU from a list.
Something like;
$OU = Read-Host (but selecting an OU from a list).
I hope this makes sense.
Thanks for your help.
Something like;
$OU = Read-Host (but selecting an OU from a list).
I hope this makes sense.
Thanks for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sure; start with this:
$OUs = Get-ADOrganizationalUnit -Filter * -Properties Description | Select-Object -Property Name, Description, DistinguishedName
$OU = $OUs | Out-GridView -Title 'Please select an OU and click OK' -OutputMode Single
If (-not $OU) {Exit 1}
"You've selected the following OU: '$($OU.DistinguishedName)'" | Write-Host
In the first line, you can of course filter further, for example with the -SearchBase or -Filter argument of Get-ADOrganizationalUnit, or by adding a Where-Clause.
ASKER
Excellent.
ASKER