I currently have 4 arrays with different names of Organizational unit from our Active Directory.
So I do a big evaluation and in order not to create a separate ForEach loop for each array (because this are like 400 lines of code) I would like to put the whole thing into a single loop.
However, I need to know when which array is run through so that I can change something for this array in certain places by IF query.
thats because not all arrays can use the code in this way and for example the searchbase for the Active Directory query must be changed for each array.
Here i created a example and described my problem in the comments. (<# #>)
$OU1="1-Users","2-Users","3-Users"
$OU2="1-Computers","2-Computers","3-Computers"
$OU3="1-ServiceAccounts","2-ServiceAccounts","3-ServiceAccounts"
foreach ($ou in $OU1 <#AND OU2,OU3#> ){
if($OU1,$OU2 <#= active#> ){
<# if this array is active - do this code #>
$SearchBase = "OU="+$ou+",OU=SUBOU,DC=intra,DC=lan"
}
if($OU3 <#= active#>){
<# if this array is active - do this code #>
$SearchBase = "OU="+$ou+",DC=intra,DC=lan"
}
<# do this code for all #>
}
I hope you understand what I mean and can help me with my problem. Thank you.
Get-Help about_Splattingfor how to construct a parameter hashtable that you can add/remove/change the values as needed before you use the splat in your cmdlet call.