Get Powershell Array Row Index

      No Comments on Get Powershell Array Row Index

 Find the Row Index of a PowerShell Array

Here’s a function that will find the index of a Powershell array row, when the column you specify is also the value you’re searching:

This function is array specific, so in the script, it will only return the index for an array “$ArrayName.” It can be duplicated per array if needed, by replacing the array name appropriately.

Let’s say we have an array with “ID”,”Name”,”Notes” as its columns and want to search by Name and find the row index where the value is “MyName”:

Get-ArrayRowIndex -Property Name -Value "MyName"

This will return the first row that equals “MyName.”

To find a reference for returning a row with WHERE-Object, and updating a specific value in an existing row: View the Update Existing Value In PowerShell Array article.

Leave a Reply

Your email address will not be published.