I have a test powershell V2 script that looks like this:
function test_args()
{
Write-Host \"here\'s arg 0: $args[0]\"
Write-Host \"here\
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-quoted string to get PowerShell to evaluate the expression and then convert the result to a string.