You are currently viewing Array And Hash Tables In PowerShell

Array And Hash Tables In PowerShell

Array And Hash Tables In PowerShell

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed break, continue, and exit statements in PowerShell.

https://cloudaffaire.com/break-continue-exit-in-powershell/

In this blog post, we will discuss Array and Hash Tables in PowerShell. Like any other scripting language, PowerShell also supports array. An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored such that the position of each element can be computed from its index tuple. The simplest type of data structure is a linear array, also called a one-dimensional array. PowerShell also supports the use of the multi-dimensional array. An array can contain a collection of different data types.

Array And Hash Tables In PowerShell:

Create An Array In PowerShell:

In PowerShell, you can create and initialize an array by assigning multiple values separated by a comma to a variable. Range operators can also be used to initialize an array. PowerShell also supports the use of sub-expression operator @(..) to create an array. You can also store the output of a cmdlet to an array.

Get Array Elements In PowerShell:

Each array elements have an associated array index with it and you can retrieve individual or range of array elements using the subsequent array index. Without the index number, the entire array elements get printed. An array index starts with 0. You can also use a negative index (starts with the end of the array) to retrieve array elements.

Create A Multi-dimensional array in PowerShell:

PowerShell also supports the use of a multi-dimensional array. A multi-dimensional array is basically an array of array.

Array Manipulation In PowerShell:

An array has multiple methods and properties that can be used to manipulate an array. You can get all the methods and properties of an array using Get-Member cmdlet.

Associative Array (Hash Table) In PowerShell:

A hash table, also known as a dictionary or associative array, is a compact data structure that stores one or more key/value pairs.

Hope you have enjoyed this article. In the next blog post, we will discuss Functions in PowerShell.

To get more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1