After trying several different ways, I need help .
I'm reading certain OUs in a domain and displaying them in a combobox:
$excludedNames = "xxx", "xxx", "xxx", "xxx"
Then the selection is displayed again at the end as a summary:Update-ComboBox $comboboxOU (Get-ADOrganizationalUnit -Filter * -SearchBase "OU=xxx,DC=xxx,DC=xxx" -SearchScope Subtree | Where-Object { $_.Name -notin $excludedNames } | Select-Object Name) -DisplayMember "Name"
This part works so far and outputs correctly. So I thought it couldn't be that hard to write the content of the $comboboxOU variable as a string to a new variable and then use it to create a new user:$comboboxOU_SelInCh={
$SumOU.Text = $comboboxOU.Text
Update-NavButtons
}
This is where I now have a problem because I'm not getting anything passed on. After running the following command to create the user:$OU = $comboboxOU.Text
$OU = Get-ADOrganizationalUnit -Filter {Name -eq $OU} -SearchBase "DC=xxx,DC=xxx"
$OU = ($OU).DistinguishedName
...I get an error that the "Path" ia wrong and the $OU variable cannot be null (which I thought was filled in above?). What's the difference between this and passing it to the $SumOU.Text variable above?Invoke-Command -ComputerName $DC -Credential $cred -ScriptBlock {
New-ADUser -Name $using:Name -GivenName $using:GivenN -Surname $using:Surname -DisplayName $using:DispName -EmailAddress $using:UsrMail -SamAccountName $using:SamAcc -UserPrincipalName "$using:SamAcc@$using:UDomain" -Department $using:Departm -Description $using:Discrip -Title $using:Titel -Company $using:Company -City $using:City -Country $using:Country -State $using:State -PostalCode $using:PostalCode -StreetAddress $using:Street -Path $using:OU -AccountPassword ("xxx" | ConvertTo-SecureString -AsPlainText -Force) -ChangePasswordAtLogon $true -Enabled $true
}
I hope you have ideas...
I've already tried the following combinations:
$OU = $comboboxOU.SelectedItem, $OU = $comboboxSalto.SelectedItem.toString() - i don't get the String in $OU.
"If I manually fill the $OU variable, it works - which means to me that the problem must lie in the transfer from the combobox to the variable. This doesn't make sense to me again, because I already pass and output the selection of the combobox as text (which works).
I hope you can help me!
Best regards.
KW