Kinook Software Forums

Kinook Software Forums (http://www.kinook.com/Forum/index.php)
-   [VBP] Third Party Tools (http://www.kinook.com/Forum/forumdisplay.php?f=3)
-   -   Strange PowerShell behavior with arguments (http://www.kinook.com/Forum/showthread.php?t=5361)

mevans 06-23-2015 02:04 PM

Strange PowerShell behavior with arguments
 
When I pass command-line arguments to PowerShell, I can see them if I do this:

foreach ($i in $args)
{Write-Host $i}

And $args.count returns the correct number.

However, whenever I try to access a specific arg, I always get an empty value. For example:
Write-Host $args[0]
Write-Host $args[1]

This always generates nothing. Even looking at various posts online, I can see maybe I needed to do it like this:

Write-Host $($args[0])
Write-Host $($args[1])

But that still returns nothing.

I finally found one notation that works:

param(
$a,
$b
)

Write-Host $a
Write-Host $b

What I don't understand is why I can't access the values from $args[0], even though I can iterate through the array and get the values?

kinook 06-23-2015 07:31 PM

[ and ] are special characters in Visual Build step properties--you need to double them to escape (i.e., $args[[0]]).
http://www.kinook.com/VisBuildPro/Ma...ershelltab.htm

mevans 06-24-2015 05:18 PM

Ahhh...thank you. I doubled them elsewhere in the script and totally missed this.


All times are GMT -5. The time now is 06:21 AM.


Copyright 1999-2019 Kinook Software, Inc.