I have a PowerShell script I am using to automate creating volumes on a SAN. The script prompts the user to enter the pertinent information: number of volumes, volume size and naming pattern. Next it should run a command on the array to create the volumes using the information provided. Here is where I am stuck. Right now the script asks the user to specify the number of volumes to create. For example let's say the user enters the number 4. I a stuck on how to take 4 and make it an array 1,2,3,4 or 7 to 1,2,3,4,5,6,7. Maybe there is an easier way to do this via counting or some other function. I am new to scripting, so any help is greatly appreciated.
# Define the number of volumes to create
$num_vols = read-host "Please enter the number of volumes"
# Define naming pattern
$vol_name = read-host "Please enter the volume naming pattern"
What I wanted to do was create a function that would basically run something like:
# Run command to create volumes on array
foreach ($i in $num_vols){
& "command to execute" $vol_name + $i
}
Thanks for the suggestions. I am now using:
# Run command to create volumes on array
foreach ($i in 1..$num_vols){
& "command to execute" $vol_name"."$i
}
Works perfectly! I can now create X volumes named VolName.1, VolName.2 and so on, where X is the number of volumes entered by the user.
1..$num_vols | % { .... }