PowerShell - Pass Multiple Elements To Array Arguments In Function

I need help passing elements to array arguments in function.

I have current script that will, accept hard-coded elements. This will change the grid color to black in Windows 7 task Manager.
$Bytes = [System.IO.File]::ReadAllBytes("C:\Windows\System32\taskmgr.exe")

$Offsets = @(0x0000B387, 0x0000FB84)
[Byte[]] $Hex_Color_Bytes = 0x00, 0x00, 0x00

For ($i = 0; $i -lt $Offsets.Length; $i++)
{
  For ($j = 0; $j -lt $Hex_Color_Bytes.Length; $j++)
  {
    $Bytes[$Offsets[$i]++] = $Hex_Color_Bytes[$j]
  }
}

[System.IO.File]::WriteAllBytes("C:\Windows\System32\taskmgr.exe", $Bytes)

Open in new window


This script does nothing? It will print the arguments, though.
$Bytes = [System.IO.File]::ReadAllBytes("C:\Windows\System32\taskmgr.exe")

Function Hex_Change_Colors([Array]$Offsets, [Byte[]]$Hex_Color_Bytes)
{
  For ($i = 0; $i -lt $Offsets.Length; $i++)
  {
    For ($j = 0; $j -lt $Hex_Color_Bytes.Length; $j++)
    {
      $Bytes[$Offsets[$i]++] = $Hex_Color_Bytes[$j]
    }
  }
  # Write-Host $Offsets, $Hex_Color_Bytes
}

Hex_Change_Colors 0x0000B387, 0x0000FB84, 0x00, 0xFF, 0x00
[System.IO.File]::WriteAllBytes("C:\Windows\System32\taskmgr.exe", $Bytes)

Open in new window


Can someone please help?

Many thanks in advance. (Apologies for confusion, new to PowerShell)
Bobby LlihAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael B. SmithManaging ConsultantCommented:
Change your function call to this:

Hex_Change_Colors @( 0x0000B387, 0x0000FB84 ) @( 0x00, 0xFF, 0x00 )

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
You do not need the @(), the commas alone are creating an array. The main point is to not use a comma between parameters - those are always separated by whitespace.
You can also use parameter names, which makes it more obvious:
Hex_Change_Colors -Offsets 0x0000B387, 0x0000FB84 -Hex_Co!or_Bytes 0x00, 0xFF, 0x00

Open in new window

0
Bobby LlihAuthor Commented:
Many Thanks :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.