Powershell How to add more values into param strings

Eaven HUANG 2,166 Reputation points
2022-02-25T01:21:33.297+00:00

Dear Experts,

We have an older script which is still running fine.
We now need to include another different OU into the script, however it seems that the $ADSearchBase variable only accepts one value?

Any idea we can add one more OU into the script to get it work?
Thanks a lot!

param( 
    [parameter(Mandatory=$false)] 
    [String] $ADSearchBase = "OU=Left,OU=Users,OU=GTIIT,DC=xxDC=com,DC=cn"
) 
 
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,526 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 46,721 Reputation points
    2022-02-25T03:33:59.367+00:00

    Define $ADSearchBase as an array of strings:

    param( 
         [parameter(Mandatory=$false)] 
         [String[]] $ADSearchBase = "OU=Left,OU=Users,OU=GTIIT,DC=xxDC=com,DC=cn", "OU=Right,OU=Users,OU=GTIIT,DC=xxDC=com,DC=cn"
     ) 
    

    Keep in mind that you can use only one value at a time in the -SearchBase parameter on, say, a Get-ADUser cmdlet. You'll have to modify the code to loop over the array and run your code as many times as there are items in the array.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.