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?
System.Array.IndexOf.IndexOf()is case-sensitive, whereas PowerShell's operators (such as-eq) are case-insensitive..Where({})array method is both fast and rather flexible.$Collection.Where({Filter code here})gives you. it otta be faster than hunting down an index to use later for accessing the desired object from an array.