• PowerShell merge arrays
    25 July

    Merge Arrays in PowerShell

    Using + Operator Use + operator to merge arrays in PowerShell. [crayon-67268b70976cd433715302/] [crayon-67268b70976d6656608431/] We used the sub-expression operator represented by @() to create two separate arrays named $array1 and $array2 (you can also create arrays without using the sub-expression operator). Note that both arrays contained string-type values. Next, we used the + operator to join […]

  • PowerShell cannot index into null array
    18 June

    Cannot Index into a Null Array in PowerShell

    If you are encountering the error message Cannot index into a null array in PowerShell, this indicates that you are trying to access an index of an array that doesn’t exist or has not been initialized yet. This error may also occur if you access the array set to $null. Let’s reproduce the error before […]

  • PowerShell add array to array
    27 May

    PowerShell Add Array to Array

    Using + Operator Use the + operator to add an array to another array. [crayon-67268b70996d3995417492/] [crayon-67268b70996d7293718104/] First, we used the array operator represented by @() to declare two arrays, $array1 and $array2, containing the values 1,2,3and 4,5,6. After that + operator is used to concatenate the two arrays together into a $newArray. In PowerShell, when […]

  • Convert Array to ArrayList in PowerShell
    16 April

    Convert Array to ArrayList in PowerShell

    One of the everyday tasks is converting an array to an ArrayList in PowerShell. It can be helpful when you need to work with dynamic data structures or manipulate data in memory. However, before we dive into how to convert an array to ArrayList, it’s essential to understand the difference between these two. An array […]

  • Split Path into Array in PowerShell
    05 April

    PowerShell Split Path into Array

    Split Path into Array in PowerShell Using Split() Method Use the Split() method to split the path into an array in PowerShell. [crayon-67268b709a0c4159154987/] [crayon-67268b709a0c7825938743/] First, we defined a $path variable and set its value to a path as demonstrated above; you can initialize it with your own path. Next, we chained the Split() method with […]

  • Get last element of array in PowerShell
    29 March

    Get Last Element of Array in PowerShell

    An array is a collection of data elements stored together under a single variable name. Unlike other programming languages, the array in PowerShell contains the values of the same or different data types. It is defined using square brackets [ ] with each element separated by a comma. The array’s index starts with zero, meaning […]

  • Check if Array contains element in PowerShell
    13 March

    Check if Array Contains Element in PowerShell

    1. Overview In this article, we will see different ways to check if array contains element in PowerShell using -contains operator, Contains() method, Where-Object cmdlet, -in operator, indexOf() method, and LINQ. 2. Introduction to Problem Statement We are given an array and element. Our goal is to check if array contains the element. For instance, […]

  • Convert Array Object to String in PowerShell
    10 March

    PowerShell Array to String

    Using Double Quotation Marks Use double quotation marks to convert array object to string in PowerShell. [crayon-67268b709a745361966653/] [crayon-67268b709a74a565421922/] First, we created an array object and saved it in the $arrayObject variable; we can also create an array object using the array operator (@()), for instance, $arrayObject = @("How", "are", "you?"). Next, we enclosed the $arrayObject […]

  • Compare Arrays in PowerShell
    14 February

    Compare Arrays in PowerShell

    In this post, we will see how to compare Arrays in PowerShell. PowerShell supports arrays with one or more dimensions and zero to many elements in each dimension. Elements inside a dimension are numbered from 0 in ascending integer order. In addition, the array subscript operator [] allows access to any particular element. PowerShell may […]