0

I'm trying to pass a string array to a function, as well as a variable (which I've made into a single element array), but i'm not sure what the format is.

Function UpdateMembership ([string[]]$arr,[string[]]$group)
{
write-host $arr[0]
write-host $arr[1]
write-host $Group[0]
}

$OUs = @(
              "test1",
              "test2"
                )
$groupname  = @("group")

UpdateMembership ($Ous, $groupname)

$groupname = @()
$Ous = @()
1
  • I didnt understand it correctly. You mean to say that you wish to update the OU and groupname based on the input that you are taking in the function? Then use for loop and update it. Or directly call @OU and @Groupname in the updatemembership function Commented Apr 26, 2019 at 9:20

2 Answers 2

1

When invoking the function, parameters are NOT enclosed in parenthese nor delimited by a comma.

Like you do it, you force ONE array to be handed over to the function.

You may use parameter names

> UpdateMembership -arr $Ous -group $groupname
test1
test2
group

or simply rely on positional order

> UpdateMembership $Ous $groupname
test1
test2
group
Sign up to request clarification or add additional context in comments.

Comments

0
Function UpdateMembership ([string[]]$arr,[string[]]$group)
{
    write-host $arr[0]
    write-host $arr[1]
    write-host $Group[0]
}

$OUs = @(
    "test1",
    "test2"
)
$groupname  = @("group")

UpdateMembership @Ous @groupname

$groupname = @()
$Ous = @()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.