• Convert String to byte array in PowerShell
    16 April

    Convert String to Byte Array in PowerShell

    Using System.Text.Encoding Class The System.Text.Encoding class converts the specified string to a byte array in PowerShell. This class can use a particular, default, or custom encoding format. Let’s see how we can use them. Use System.Text.Encoding Class with a Particular Encoding Use the System.Text.Encoding class with specific encoding to convert a string to byte array […]

  • PowerShell check if file contains string
    14 April

    PowerShell Check If File Contains String

    Using Select-String Cmdlet Use the Select-String cmdlet to check if the specified file contains the given string in PowerShell. [crayon-6750138c0d238027409391/] [crayon-6750138c0d242531432138/] First, we declared and initialized a variable named $path containing the location of the file1.txt file. Then, we created another variable called $string and set its value with "customers"; this is the value we […]

  • Powershell convert Guid to String
    14 April

    PowerShell Convert Guid to String

    💡TL;DR Use the ToString() method on System.Guid to convert a GUID to a string in PowerShell. [crayon-6750138c0d563853791832/] [crayon-6750138c0d568240032217/] Before diving into the solutions, let’s understand what GUID is. In PowerShell, a Globally Unique Identifier (GUID) is a 128-bit identifier used to identify objects uniquely—for instance, folders, files, registry keys, and other system resources. Remember, GUIDs […]

  • Generate random String in PowerShell
    10 April

    Generate Random String in PowerShell

    Using [System.Guid] Class To generate a random string in PowerShell: Create a globally unique identifier using the NewGuid() method. Use the ToString() method to transform the GUID (created in the previous step) to String format. Use the Write-Host cmdlet to print the random string. [crayon-6750138c0d78a612160993/] [crayon-6750138c0d78f739098720/] The New-Guid() is a static method of [System.Guid] class […]

  • 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-6750138c0d9a8481828522/] [crayon-6750138c0d9ac592019699/] 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 […]

  • Check if String contains Number in PowerShell
    14 February

    Check if String Contains Number in PowerShell

    Using Regular Expression We use regular expressions whenever we are required to look for specific patterns in the text. The regular expressions, also known as regex, comprise operators, literal characters, and other constructs. PowerShell has various cmdlets and operators that allow us to use regex with them; some of them are given below: Using -match […]