I'd like to compare the OU-Path of an AD-User and create an autoselection of the correct OU in an combobox.
My idea is to write the code as a function where it searchs for all organizationalUnits and put them into a hashtable.
The Script I wrote for it was tested in PowerShell ISE and it worked perfectly, but copying it to the PowerShell Studio drives me crazy.
Everytime when it comes to write data into the hashtable it doesn't work.
When I want to see an output - it's empty.
- $OUPfadeStandortearray = $null
- $Script:OUHash = $Null
- $OUPfadeStandorte = Get-ADObject -Filter 'ObjectClass -eq "organizationalUnit" -and name -like "*Mitarbeiter*"' | sort name
- foreach ($_ in $OUPfadeStandorte)
- {
- $OUPfadeStandorteAbfrage = Get-ADObject -Filter 'ObjectClass -eq "organizationalUnit"' -SearchBase $_
- $OUPfadeStandortearray += $OUPfadeStandorteAbfrage
- }
- foreach ($_ in $OUPfadeStandortearray)
- {
- $Name = $_.name | Out-String
- $OU = $_.DistinguishedName | Out-String
- ##############this does not work in PowerShell Studio#####################
- $Script:OUHash += @{ $_.name = $_.DistinguishedName }
- ###############################################################
- }
- $Script:OUHash
Thanks for your help!