accessing the $args array in powershell

Try this instead:

function test_args()
{
  Write-Host "here's arg 0: $($args[0])"
  Write-Host "here's arg 1: $($args[1])"
}

test_args foo bar

Note that it is $args and not $arg. Also when you use a PowerShell variable in a string, PowerShell only substitutes the variable’s value. You can’t directly use an expression like $args[0]. However, you can put the expression within a $() sub-expression group inside a double-

Leave a Comment

tech