I'm using Invoke-Command, but this question can be relevant to any command using splat. I essentially want to pass two sets of variables that will be useful in the splat command, but I'm not sure how I can do this.
In the code below, the Invoke-Command successfully connects to both servers, but the output I get is "Server1 Info" from both servers, which makes sense since the code is reading it like I'm trying to pass two arguments to both servers and it is taking what is in the first argument and writing it to host. What I really want it to do though is only pass one argument each time and to move down the list of which argument is being passed as it connects to successive servers.
$ServerList = "Server1","Server2"
$ServerArgs = "Server1 Info","Server2 Info"
$SB = {
param($Arg1)
Write-Host $Arg1
}
$SplatInfo = @{
ComputerName = $ServerList
ArgumentList = $ServerArgs
}
Invoke-Command @SplatInfo -ScriptBlock $SB