Link to home
Start Free TrialLog in
Avatar of Bobby Llih
Bobby Llih

asked on

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)
ASKER CERTIFIED SOLUTION
Avatar of Michael B. Smith
Michael B. Smith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bobby Llih
Bobby Llih

ASKER

Many Thanks :)