0

This is a stripped down version of the code I need to run. I've been able to determine, with this test code, that it's happening as soon as the array enters the function. Am I doing something wrong when I pass the array? This seems like it should be simple, but I'm stuck. Doing Return ,$List doesn't make any difference.

Script:

function ProcessSkills{
    param([Object[]]$List)
    Write-Host $List.GetType()
    Write-Host $List.Count
    Write-Host $List
    $List += 11
    Write-Host $List.GetType()
    Write-Host $List.Count
    Write-Host $List
    return $List
}

$skillList = @()
Write-Host
Write-Host "Start"
Write-Host 
Write-Host $skillList.GetType()
Write-Host $skillList
Write-Host $skillList.Count
$newSkillList = ProcessSkills -$skillList $skillList
$skillList = $newSkillList
Write-Host $skillList.GetType()
Write-Host $skillList
Write-Host $skillList.Count
$newSkillList = ProcessSkills -$skillList $skillList
$skillList = $newSkillList
Write-Host $skillList.GetType()
Write-Host $skillList
Write-Host $skillList.Count
$newSkillList = ProcessSkills -$skillList $skillList
$skillList = $newSkillList
Write-Host $skillList.GetType()
Write-Host $skillList
Write-Host $skillList.Count

Output:

Start

System.Object[]

0
System.Object[]
1
-
System.Object[]
2
- 11
System.Object[]
- 11
2
System.Object[]
1
-- 11
System.Object[]
2
-- 11 11
System.Object[]
-- 11 11
2
System.Object[]
1
--- 11 11
System.Object[]
2
--- 11 11 11
System.Object[]
--- 11 11 11
2
2
  • 1
    Can you rephrase what you're asking for? I am genuinely confused. Commented Feb 25, 2022 at 16:33
  • 1
    The $ is not part of the parameter name, change all instance of ProcessSkills -$skillList $skillList to ProcessSkills -List $skillList Commented Feb 25, 2022 at 16:37

1 Answer 1

1

Does this address the problem?

function ProcessSkills{
    param([Object[]]$List)
    $List += 11
    return ,$List
}

$skillList = @()
$skillList = ProcessSkills  $skillList
$skillList = ProcessSkills  $skillList
$skillList = ProcessSkills  $skillList
Sign up to request clarification or add additional context in comments.

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.