none
New-MailBox OrganizationalUnit issues RRS feed

  • Question

  • Hi,

    I'm probably being daft but I cannot seem to get the -OrganizationalUnit parameter on the New-Mailbox function to work.

    I have tried "-OrganizationalUnit "Process Industried"" which is the name of an OU

    as well as "-OrganizationalUnit "OU=Name,OU=Multi-Channel,OU=Business Units,DC=sanderson,DC=lan""

    but neither are working and the users are just getting thrown into the default users OU. Any help would be greatly appreciated  :)

    Kind regards,

    Mark Harwood

    Tuesday, August 15, 2017 9:17 AM

Answers

  • This seems to work with a switch

    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    
    Function GetOU($cbOU)
    {
    $Org = $comboBox1.Text
    $OrgUnit = Switch ($Org)
    {
    Prod {'OU=Production,OU=Manufacturing,DC=DOMAIN,DC=COM'}
    Test  {'OU=Test,OU=Manufacturing,DC=DOMAIN,DC=COM'}
    Dev {'OU=Dev,OU=Manufacturing,DC=DOMAIN,DC=COM'}
    }
    
    write-host "selected OU =  " $OrgUnit 
    }
    
    $Form1 = New-Object System.Windows.Forms.Form
    $Form1.ClientSize = New-Object System.Drawing.Size(407, 390)
    $form1.topmost = $true
    $OUs = @('Prod','Dev','Test')
    $comboBox1 = New-Object System.Windows.Forms.ComboBox
    $comboBox1.Location = New-Object System.Drawing.Point(25, 55)
    $comboBox1.Size = New-Object System.Drawing.Size(350, 310)
    foreach($Ou in $OUs)
    {
      $comboBox1.Items.add($Ou)
    }
    $Form1.Controls.Add($comboBox1)
    
    $Button = New-Object System.Windows.Forms.Button
    $Button.Location = New-Object System.Drawing.Point(25, 20)
    $Button.Size = New-Object System.Drawing.Size(98, 23)
    $Button.Text = "Output"
    $Button.add_Click({GetOU($CbOU)})
    $Form1.Controls.Add($Button)
    
    
    $Form1.Controls.Add($label)
    
    [void]$form1.showdialog()

    Tuesday, August 15, 2017 2:07 PM

All replies

  • try single quotes -OrganizationalUnit 'Process Industried'

    Tuesday, August 15, 2017 10:06 AM
  • Hi Simbrook2,

    thanks for the response. I have tried that:

    get-mailbox -OrganizationalUnit 'OU=Production,OU=Manufacturing,DC=DOMAIN,DC=COM'

    and it has worked. However I use a variable to fill in this bit (called $OrgUnit) which comes from a switch function. However, the switch function doesn't seem to be working as the variable doesn't get a string.

    So far I have tried:

    switch ($OUComboBox.Text){

     "Process Industries"{set-variable -name "OrgUnit" -Value 'OU=Production.....'

    }

    and:

    switch ($OUComboBox.Text){

     "Process Industries" {$OrgUnit = "OU=Production....."

    }

    but neither work. Sorry for the long response and not formatting the code, every time I do I shoots to the top of the response and messes up the other text :(

    Tuesday, August 15, 2017 11:13 AM
  • Ok I did this without a switch but it dows populate the variable with the selected OU from the dropdown so may help you

    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    
    Function GetOU($cbOU)
    {
    $OrgUnit = $comboBox1.Text
    write-host "selected OU =  " $OrgUnit 
    }
    
    $Form1 = New-Object System.Windows.Forms.Form
    $Form1.ClientSize = New-Object System.Drawing.Size(407, 390)
    $form1.topmost = $true
    $OUs = @('OU=Production,OU=Manufacturing,DC=DOMAIN,DC=COM','OU=Dev,OU=Manufacturing,DC=DOMAIN,DC=COM','OU=Test,OU=Manufacturing,DC=DOMAIN,DC=COM')
    $comboBox1 = New-Object System.Windows.Forms.ComboBox
    $comboBox1.Location = New-Object System.Drawing.Point(25, 55)
    $comboBox1.Size = New-Object System.Drawing.Size(350, 310)
    foreach($Ou in $OUs)
    {
      $comboBox1.Items.add($Ou)
    }
    $Form1.Controls.Add($comboBox1)
    
    $Button = New-Object System.Windows.Forms.Button
    $Button.Location = New-Object System.Drawing.Point(25, 20)
    $Button.Size = New-Object System.Drawing.Size(98, 23)
    $Button.Text = "Output"
    $Button.add_Click({GetOU($CbOU)})
    $Form1.Controls.Add($Button)
    
    $label = New-Object System.Windows.Forms.Label
    $label.Location = New-Object System.Drawing.Point(70, 90)
    $label.Size = New-Object System.Drawing.Size(350, 100)
    $label.Text = ""
    $Form1.Controls.Add($label)
    
    [void]$form1.showdialog()

    Tuesday, August 15, 2017 12:40 PM
  • BRILLIANT!

    You have pretty much exactly what I have but I don't want the exact Distinguishednames to be displayed. Instead I use the switch parameter to change the variable $OrgUnit depending on the input from the drop down list. That way I can have more human friendly names in the drop down list.

    Can you think of any reason why the switch parameter isn't working? After running the script I have a value for the menu input but nothing for the $OrgUnit variable from the switch statement :/

    Thank you for your help so far :)

    Tuesday, August 15, 2017 1:40 PM
  • This seems to work with a switch

    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    
    Function GetOU($cbOU)
    {
    $Org = $comboBox1.Text
    $OrgUnit = Switch ($Org)
    {
    Prod {'OU=Production,OU=Manufacturing,DC=DOMAIN,DC=COM'}
    Test  {'OU=Test,OU=Manufacturing,DC=DOMAIN,DC=COM'}
    Dev {'OU=Dev,OU=Manufacturing,DC=DOMAIN,DC=COM'}
    }
    
    write-host "selected OU =  " $OrgUnit 
    }
    
    $Form1 = New-Object System.Windows.Forms.Form
    $Form1.ClientSize = New-Object System.Drawing.Size(407, 390)
    $form1.topmost = $true
    $OUs = @('Prod','Dev','Test')
    $comboBox1 = New-Object System.Windows.Forms.ComboBox
    $comboBox1.Location = New-Object System.Drawing.Point(25, 55)
    $comboBox1.Size = New-Object System.Drawing.Size(350, 310)
    foreach($Ou in $OUs)
    {
      $comboBox1.Items.add($Ou)
    }
    $Form1.Controls.Add($comboBox1)
    
    $Button = New-Object System.Windows.Forms.Button
    $Button.Location = New-Object System.Drawing.Point(25, 20)
    $Button.Size = New-Object System.Drawing.Size(98, 23)
    $Button.Text = "Output"
    $Button.add_Click({GetOU($CbOU)})
    $Form1.Controls.Add($Button)
    
    
    $Form1.Controls.Add($label)
    
    [void]$form1.showdialog()

    Tuesday, August 15, 2017 2:07 PM
  • Thank you for all your help Simbrook2!

    What I realised once I had pulled all my hair out was that I had the switch statement at the same point in the script that the form was being created. Meaning that it tried to do the switch argument before the form had been loaded and values had been entered... obviously resulting in nothing except the loss of my own sanity :)

    Thank you for the help, just an FYI this is what I ended up with:

    $org = $OUComboBox.Text
    $OrgUnit = switch ($org){
        'Process Industries'{'OU=Process Industries,OU=Manufacturing,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Production & Print'{'OU=Production & Print,OU=Manufacturing,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Company'{'OU=Company,OU=Manufacturing,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Mail Order'{'OU=Mail Order,OU=Multi-Channel,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Company2'{'OU=Company2,OU=Multi-Channel,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Company3'{'OU=Company3,OU=Multi-Channel,OU=Business Units,DC=DOMIN,DC=lan'}
        'Company4'{'OU=Company4,OU=Multi-Channel,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Wholesale & Distribution'{'OU=Wholesale & Distribution,OU=Multi-Channel,OU=Business units,DC=DOMAIN,DC=lan'}
        'Finance & Admin'{'OU=Finance & Admin,OU=Sanderson Group,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Management'{'OU=Management,OU=Sanderson Group,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Marketing'{'OU=Marketing,OU=Sanderson Group,OU=Business Units,DC=DOMAIN,DC=lan'}
        'Training'{'OU=Training,OU=Sanderson Group,OU=Business Units,DC=DOMAIN,DC=lan'}
    }
    

    Thanks for the help Simbrook2, I suppose if I had shown more of my script we could have figured that our quicker together. My Bad...my VERY bad :)



    Tuesday, August 15, 2017 3:32 PM