• 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-662edb590868c410387686/] [crayon-662edb5908693478692873/] 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 […]

  • Change directory in PowerShell
    29 March

    Change Directory in PowerShell

    Using Set-Location Cmdlet Use the Set-Location cmdlet to change directory in PowerShell. [crayon-662edb5908a70264548586/] [crayon-662edb5908a76672548277/] Above, we have used the Set-Location cmdlet to change the directory from C:\ to D:\ drive. In PowerShell, Set-Location is used to specify the current working directory. First, the working directory was C:\Users\DELL after using Set-Location -Path D:\ current working directory […]

  • 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 […]

  • Get exit code of Last command in PowerShell
    28 March

    Get Exit Code of Last Command in PowerShell

    We can use different solutions to get the exit code of the last command in PowerShell, but before that, it is essential to know what does exit command means. The exit command terminates the current PowerShell script or session in PowerShell. When an exit command is executed, the PowerShell session or script will be immediately […]

  • Select-String from file with regex in PowerShell
    19 March

    Select-String from File with Regex in PowerShell

    Using Select-String with Regex to Find Patterns from File There are multiple scenarios where we can use Select-String with a regular expression (also called regex) to search for particular patterns from file(s). Some of them are given below: Search a specific pattern in a single file Search a particular pattern in multiple files Search multiple […]

  • Split text file on Newline in PowerShell
    19 March

    Split Text File on NewLine in PowerShell

    Using Get-Content Cmdlet We can use multiple ways to split the specified text file into an array based on every new line. To practice those methods and commands, we will use the file.txt file having the following content. Of course, you can also create or use your text file. [crayon-662edb590a2ea004715792/] Let’s continue learning the solutions […]

  • Print Object in PowerShell
    19 March

    Print Object in PowerShell

    Print Object’s Properties in Powershell In PowerShell, an object is a data structure that contains properties and methods. An object is essentially an instance of a .NET class and can be created using the New-Object cmdlet. PowerShell objects are used extensively in PowerShell scripting. For example, many cmdlets return objects as output, which can be […]

  • Find String in File in PowerShell
    15 March

    PowerShell – Find String in File

    1. Overview Searching for strings in text files is a common task in PowerShell, used in scenarios like log file analysis and configuration file searches. This article explores various methods for finding strings in files, including both case-sensitive and case-insensitive approaches. 2. Introduction to Problem Statement Let’s consider a log file named server.log: [crayon-662edb590aa82336574103/] Our […]

  • Find Position of Character in String in PowerShell
    13 March

    Find Position of Character in String in PowerShell

    Using IndexOf() Method Use the IndexOf() to find the position of character in string in PowerShell. indexOf() method returns index of first occurrence of character in String. [crayon-662edb590acd1613783760/] [crayon-662edb590acd5908365068/] In the above code, the output indicates that the input string is Hello, world! and the position of the comma character in the string is 5. […]