I created a function to find an item in an array so I can update it.
function Get-ArrayRowIndex {
param(
[parameter(mandatory = $true)][array]$Property,
[parameter(mandatory = $true)][string]$Value
)
#Loop through array,incrementing index until value is found. Jordan wrote this and I refined it.
[int]$index = 0
while ($index -lt ($Property.count)) {
if ($Property[$index] -eq $Value) {
break
}
$index++
}
return [int]$index
}
The problem is when the object is not found the function returns the total number of items in the array. How can I return an error if not found?