I'm attempting to create an onboarding script to automate the AD account creation process. Within the script I would like to use the command Get-ADOrganizationalUnit -Filter 'Name -like "\*"'
to get a list of all OUs, then generate a selection list within the PowerShell script to go with the names of each OU. Once the name is selected I would like to set a variable equal to that OUs distinguishedname. Any suggestions on the best way to accomplish this?
CodePudding user response:
You can use Out-GridView
with the -PassThru
switch to allow the, not sure if "the best way" but is an easy and friendly alternative.
$ous = Get-ADOrganizationalUnit -Filter 'Name -like "\*"'
$choice = $ous | Select-Object Name, DistinguishedName | Out-GridView -PassThru
if($choice) { # if the user selected an item from the DGV and pressed `OK`
$choice.DistinguishedName
}
else { # user clicked `Cancel` or closed the DGV
exit
}