The system has
enforced the fact that you are trying to assign a non-integer to a variable that is supposed
to hold only integers. This way, you can go into the code and immediately and see that
the error is caused by the fact that you tried to assign "Steve" to $a instead of $s. You
simply need to correct that mistake and the script will operate as expected.
445 Chapter 13: Windows PowerShell
Interestingly enough, no special naming convention is needed to define an array. An
array is generally a simple data structure in which a group of values or objects can be
accessed using the same name but using indexes to access each individual element. If
you??™ve looked at VBScript code, you have undoubtedly seen something similar to this:
Dim myArr(2)
myArr(0) = "first"
myArr(1) = "second"
myArr(2) = "third"
WScript.Echo myArr(1)
This isn??™t a VBScript tutorial, so we won??™t go into this example in great detail; basically,
this code defines an array containing three elements (even though there??™s a 2 in the
parentheses since the 2 signifies the index of the last element starting from 0). You then
assign values to each element and then output the value of myArr at index 1, which in
this case would be the string second.
The following code snippet shows how arrays are dealt with in Windows PowerShell:
$myArr = "first","second","third"
$myArr[1] = "2nd"
write-host $myArr
Common Windows PowerShell Variable Types
Since Windows PowerShell is built on top of the .
Pages:
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473