• Count occurrences of character in String in PowerShell
    14 February

    Count Occurrences of Character in String in PowerShell

    Using the -replace Operator To count the occurrences of a character in a String in PowerShell: Use the -replace operator to replace the occurrences of the specified character with an empty string and store the result in a temporary string. Use the .Length property to get the length of the original and the temporary string. […]

  • Run PowerShell Script from batch file
    13 February

    Run PowerShell Script from Batch File

    We have to follow a few steps given below to run the specified PowerShell script from a batch file. Create a PowerShell Script. Create a Batch File. Run the Batch file to execute PowerShell Script from it (batch file). Creating a PowerShell Script Create a .ps1 script file containing the following command. [crayon-67bad083e8b45759490295/] We saved […]

  • Overwrite File in PowerShell
    07 February

    Overwrite File in PowerShell

    Using Set-Content Cmdlet Use the Set-Content cmdlet to overwrite a file in PowerShell. [crayon-67bad083e9a5d234323108/] [crayon-67bad083e9a66262880999/] Initially, the File1.txt file had Hi! as its content, but later it was overwritten, and now it contains the content as shown in the above output. The Set-Content is known as the string-processing cmdlet, which we use to overwrite the […]

  • Remove spaces from String in PowerShell
    07 February

    Remove Spaces from String in PowerShell

    Using -replace Operator Use the -replace operator to remove spaces from a string in PowerShell. [crayon-67bad083ea873472553206/] [crayon-67bad083ea879356266248/] First, we must understand that replacing does not mean removing something but replacing one thing with another. Similarly, we used the -replace operator to replace all occurrences of whitespace character (" ") with an empty string (""), which […]

  • Return Boolean from Function in PowerShell
    07 February

    Return Boolean from Function in PowerShell

    Using Predefined Variables – $True and $False To return Boolean from function in PowerShell, use predefined variables: $True, $False. [crayon-67bad083eaeda992637573/] [crayon-67bad083eaedf637546887/] In PowerShell, a Boolean value can be either True or False. However, the Boolean data type represents the true/false conditions for use in conditional statements, comparisons, and logical operations. The following values are True […]

  • Remove Item from Array in PowerShell
    07 February

    PowerShell – Remove Item from Array

    Please note that we will use ArrayList instead of Array here as Array is fixed size and it can not be altered. Using Remove() Method Use the Remove() method to eliminate an item from an ArrayList in PowerShell. [crayon-67bad083eb8f2007193241/] [crayon-67bad083eb8f8208109309/] In the above example, the courses titled Maths, Chemistry, and Physics are added to an […]

  • Remove double quotes from String in PowerShell
    06 February

    Remove Double Quotes from String in PowerShell

    Using Replace() Method Use the Replace() method to remove double quotes from a string in PowerShell. [crayon-67bad083ec7da912202931/] [crayon-67bad083ec7e1514305288/] For the above code, we used the Replace() method to replace doubles quotes with empty space. The Replace() method took two arguments: First was the character or string that we wanted to replace – Double quotes (`") […]

  • Capitalize First Letter in PowerShell
    06 February

    PowerShell – Capitalize First Letter

    Capitalize First Letter in PowerShell Using Substring() with ToUpper() Method To capitalize the first letter of String in PowerShell: Capitalize first letter using ToUpper() chained Substring() method via dot notation. Save the rest of the string in a variable. Use concatenation operator (+) to concatenate the strings, received from step 1 & 2. [crayon-67bad083ecd9d144340057/] [crayon-67bad083ecda2434737725/] […]

  • Get Object type in PowerShell
    06 February

    Get Object Type in PowerShell

    Using GetType() Method Use the GetType() method to get the object’s data type in PowerShell. [crayon-67bad083ed63d966233835/] [crayon-67bad083ed642606225865/] We used the GetType() method to get the data type of an object we saved in the $string variable. The returned object will be an instance of the System.Type class, which contains information about the type, such as […]