Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Index was outside bounds of array error

$
0
0

So I have the below code and I'm trying to enter values into an array using input from the user. Whenever I run the script, it goes through it all, but spits out an error before the "Write-Host" line saying the index was outside bounds of the array. I even output $i and it shows that it increments properly, so I'm not sure what it's trying to say. Powershell is telling me the error is at the line "$LogName[$i] = Read-Host -Prompt "Enter the name of Log #$j"

 
$LogName = @() #Declaration of an empty array 
$NumberOfLogs = Read-Host -Prompt "How many logs do you want to retrieve?"

for ($i=0
$i
-lt $NumberOfLogs
$i++)
{
$j = $i+1

$LogName [$i] = Read-Host -Prompt "Enter name of Log #$j"

Write-Host $LogName[$i]
}




Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>