Convert Strings to Uppercase, Lowercase and Title Case in PowerShell

Convert strings to uppercase, lowercase and title case in PowerShell

To convert a string to uppercase or lowercase in PowerShell, call its .ToUpper() or .ToLower() method. Both return a new string and leave the original alone: Output: Title case and camelCase take a bit more work, and one common trick behaves differently in Windows PowerShell 5.1. I ran every example in PowerShell 7.6 and 5.1. … Read more

How to Replace Text in Strings Using PowerShell

Replace text in strings using PowerShell

To replace text in a string in PowerShell, use the .Replace() method or the -replace operator. Both return a new string with the changes: Output: They look interchangeable, but they aren’t. .Replace() matches exact text and cares about case. -replace uses regular expressions and ignores case. I ran every example in PowerShell 7.6 and Windows … Read more

How to Trim Strings in PowerShell

Trim strings in PowerShell

To trim a string in PowerShell, call .Trim() to remove spaces from both ends, or .TrimStart() and .TrimEnd() for one side only: Output: Below I cover trimming specific characters, the first or last few characters, and text before or after a character. I ran every example in PowerShell 7.6 and Windows PowerShell 5.1, and I … Read more

How to Concatenate Strings in PowerShell

Concatenate strings in PowerShell

To concatenate strings in PowerShell, put the variables inside double quotes, or join them with the + operator. The -f format operator works too: Output: All three give the same result here. The differences show up with numbers, dates, object properties and loops. I ran every example in PowerShell 7.6 and Windows PowerShell 5.1. Concatenate … Read more

PowerShell Arithmetic Operators: +, -, *, /, %, ++ and More

PowerShell arithmetic operators examples

PowerShell arithmetic operators are + for addition, – for subtraction, * for multiplication, / for division and % for the remainder (modulus). They work on numbers the way you’d expect: Output: They also have a few PowerShell-specific habits, like division that returns decimals and + that joins strings. I ran every example in PowerShell 7.6 … Read more

PowerShell IsNullOrEmpty: Check if a Variable Is Null or Empty

PowerShell IsNullOrEmpty and null checks

To check if a string is null or empty in PowerShell, use [string]::IsNullOrEmpty($value). It returns True for $null and for an empty string, and False for anything else: Output: That covers most scripts. Below I compare it with the other null checks, since each one treats values like spaces and 0 differently. I ran every … Read more

How to Get Unique Values from CSV Using PowerShell?

Get Unique Values from CSV Using PowerShell

One of my clients was working on a CSV file, and they were required to find unique values from that CSV file. I suggested using PowerShell and told them a few methods. In this tutorial, I will explain to you four simple and useful methods to get unique values from CSV using PowerShell. Get Unique … Read more

How To Create File If Not Exists In PowerShell? [4 Methods]

Create File If Not Exists In PowerShell

One of my clients recently required me to create a file if it doesn’t exist. PowerShell is the best option for this kind of requirement. In this tutorial, I will show you different methods to check for the existence of a file and create it if it doesn’t exist using PowerShell. To create a file … Read more

How to Copy and Rename Files in PowerShell?

Copy and Rename Files in PowerShell

In this article, I will explain various methods to copy and rename files using PowerShell, providing examples and complete scripts to help you understand better. To copy and rename a file in PowerShell, you can use a combination of the Copy-Item and Rename-Item cmdlets. First, use Copy-Item to copy the file to the desired location, … Read more