Home > Net >  Selecting OU from if statement in function
Selecting OU from if statement in function

Time:10-02

I am trying to change the OU path of the new user being made in the function of creating the user. I am running into the issue of the OU path coming back as NULL with this if statement and am unsure why. Any help would be great!

$dropdown_FirstOU = New-Object System.Windows.Forms.ComboBox
$dropdown_FirstOU.Location = New-Object System.Drawing.Size(55,110)
$dropdown_FirstOU.Size = New-Object System.Drawing.Size(280,40)
$dropdown_FirstOU.DropDownStyle = System.Windows.Forms.ComboBoxStyle]::DropDownList
$dropdown_FirstOU.Items.AddRange($Sites)
$Form_SelectOU.Controls.Add($dropdown_FirstOU)

if ($dropdown_FirstOU -eq "Aberdeen") {

    $OU = "OU=Aberdeen,OU=UK,DC=Kuehne-Nagel,DC=local"

} elseif ($dropdown_FirstOU -eq "Kingpin") {
   
    $OU = "OU=Kingpin,OU=UK,DC=Kuehne-Nagel,DC=local"

}

CodePudding user response:

Found out the issue, I wasn't adding the .Text after the dropdown combo box so the script wasn't reading the text in the combo box!

if ($dropdown_FirstOU.Text -eq "Aberdeen") {

    $OU = "OU=Aberdeen,OU=UK,DC=Kuehne-Nagel,DC=local"

} elseif ($dropdown_FirstOU.Text -eq "Kingpin") {

    $OU = "OU=Kingpin,OU=UK,DC=Kuehne-Nagel,DC=local"

}

CodePudding user response:

I have tested in my environment.

$OU is null because the value of $dropdown_FirstOU is neither Aberdeen nor Kingpin.

If the $dropdown_FirstOU vaule is Aberdeen, the $OU value will be OU=Aberdeen,OU=UK,DC=Kuehne-Nagel,DC=local

Similarly for the Kingpin.

enter image description here

  • Related