powershell command line variables 1

powershell command line variables

write-host "There are a total of $($args.count) arguments"
for ( $i = 0; $i -lt $args.count; $i++ ) {
    write-host "Argument  $i is $($args[$i])"

Here is what the above code is Doing:
1. We’re using the $args variable to get the arguments passed to the script.
2. We’re using the $args.count property to get the number of arguments passed to the script.
3. We’re using a for loop to iterate through the arguments.
4. We’re using the $args[$i] syntax to get the value of the argument at the current index.
5. We’re using the write-host cmdlet to display the argument value.

Similar Posts