Recently, I was working on a data migration project where I needed to process a large CSV file containing semicolon-delimited values in several columns. I quickly realized that knowing how to split strings by semicolons in PowerShell would be very useful for this.
PowerShell offers multiple methods to split strings by delimiters like semicolons.
In this tutorial, I will explain several practical ways to split strings by semicolons in PowerShell based on my decade of experience. Let’s dive in!
Split a String by Semicolon in PowerShell
Before we get into the specific methods, it’s important to understand what string splitting actually does.
When you split a string by a semicolon, PowerShell divides the original text at each semicolon character and returns an array of substrings. This is extremely useful when working with data that uses semicolons as separators.
Below are the methods to split a string by semicolon in PowerShell.
Method 1: Using the -Split Operator
The -Split operator is one of the most common and straightforward ways to split a string in PowerShell. Here is the complete script to split a string by semicolon using PowerShell.
$emailList = "john.doe@example.com;jane.smith@example.com;robert.johnson@example.com"
$emails = $emailList -split ";"
$emailsWhen you run this code, PowerShell will output:
john.doe@example.com
jane.smith@example.com
robert.johnson@example.comThe -Split operator is case-sensitive by default. If you need case-insensitive splitting, you can use the -isplit operator instead.
You can see the exact output in the screenshot below:

Check out How to Split String by Space in PowerShell
Method 2: Using the String.Split() Method
Another common approach is to use the .Split() method, which is part of the String class in .NET. You can use the String.Split() method to split a string by using a semicolon.
$statesList = "New York;California;Texas;Florida;Illinois"
$states = $statesList.Split(";")
$statesThis will give you an array containing:
New York
California
Texas
Florida
IllinoisThe .Split() method is slightly more flexible as it allows you to split by multiple delimiters simultaneously:
$mixedData = "New York;California,Texas:Florida;Illinois"
$mixedStates = $mixedData.Split(";", ",", ":")
$mixedStatesRead Split a String and Get the Second Element in PowerShell
Method 3: Using the Split() Method with Options
If you need more control over the splitting process, you can use additional parameters with the Split() method. Here is an example.
$addressData = "123 Main St;;New York;NY;10001"
$addressParts = $addressData.Split(";", [StringSplitOptions]::RemoveEmptyEntries)
$addressPartsThe output will be:
123 Main St
New York
NY
10001Notice that the empty entry between “123 Main St” and “New York” is removed because we used the RemoveEmptyEntries option.
You can see the exact output in the screenshot below:

Read PowerShell Split String by Comma
Method 4: Splitting and Processing in a Pipeline
PowerShell’s pipeline functionality allows you to split strings and process each part in one elegant command:
$productList = "Laptop;Smartphone;Tablet;Headphones;Keyboard"
$productList -split ";" | ForEach-Object { "Product: $_" }This produces:
Product: Laptop
Product: Smartphone
Product: Tablet
Product: Headphones
Product: KeyboardThis approach is particularly useful when you need to perform operations on each element after splitting.
You can see the exact output in the screenshot below:

Check out How to Split Strings by Newlines in PowerShell?
Real-World Example: Process CSV Data with Semicolon Delimiters
Let’s look at a practical example. Suppose you have a CSV file with semicolon delimiters (common in European data formats) and need to process it:
$csvContent = @"
Name;Department;Position;Salary
John Smith;Marketing;Director;120000
Sarah Johnson;IT;Developer;95000
Michael Brown;Finance;Analyst;85000
"@
$csvContent -split "`n" | ForEach-Object {
$rowData = $_ -split ";"
# Skip the header row
if ($rowData[0] -ne "Name") {
[PSCustomObject]@{
Name = $rowData[0]
Department = $rowData[1]
Position = $rowData[2]
Salary = [int]$rowData[3]
}
}
} | Sort-Object -Property Salary -DescendingThis script:
- Splits the CSV content by newlines
- For each line, splits by semicolons
- Creates custom objects for each employee (skipping the header)
- Sorts employees by salary in descending order
The output would be:
Name Department Position Salary
---- ---------- -------- ------
John Smith Marketing Director 120000
Sarah Johnson IT Developer 95000
Michael Brown Finance Analyst 85000Read How to Split a String by Word in PowerShell?
Method 5: Using ConvertFrom-Csv with Custom Delimiter
If you’re specifically working with CSV-like data, PowerShell has a built-in cmdlet that can handle custom delimiters:
$semicolonCSV = @"
Name;Age;City
John Doe;32;New York
Jane Smith;28;Los Angeles
Robert Johnson;45;Chicago
"@
$people = $semicolonCSV | ConvertFrom-Csv -Delimiter ";"
$peopleThis outputs a table of objects with properties for each column:
Name Age City
---- --- ----
John Doe 32 New York
Jane Smith 28 Los Angeles
Robert Johnson 45 ChicagoHere is the output in the screenshot below:

You can then access individual properties:
$people | ForEach-Object { "$($_.Name) lives in $($_.City)" }Method 6: Splitting with Regular Expressions
For more complex splitting requirements, you can use regular expressions with the -split operator:
$complexData = "value1;value2;;value3; value4; value5"
$parts = $complexData -split ";+" | Where-Object { $_ -match "\S" }
$partsThis splits by one or more semicolons and filters out entries that are just whitespace, giving you:
value1
value2
value3
value4
value5Check out Split a String into Variables in PowerShell
Common Problems and Solutions
Now, let me show you some common problems and solutions that you may face while splitting a string using a semicolon in PowerShell.
Handle Empty Elements
When splitting strings, you might encounter empty elements if there are consecutive delimiters:
$data = "item1;;item2;item3"
$items = $data -split ";"
$items.Count # Returns 4
$items # Shows an empty string at index 1To handle this, you can either:
- Use RemoveEmptyEntries as shown earlier
- Filter the results after splitting:
$items = $data -split ";" | Where-Object { $_ -ne "" }Deal with Semicolons in Content
If your data might contain semicolons as part of the content (not just as delimiters), you’ll need more sophisticated parsing. Consider this example with quoted values:
$quotedData = 'value1;"value2;with;semicolons";value3'
# Simple splitting won't work correctly here
$wrongSplit = $quotedData -split ";"
# A more complex approach is needed
$pattern = '(?<=^|;)(?:"([^"]*)"|((?:[^;"]|"[^"]*")+))(?=;|$)'
$correctSplit = [regex]::Matches($quotedData, $pattern) | ForEach-Object {
if ($_.Groups[1].Success) { $_.Groups[1].Value }
else { $_.Groups[2].Value }
}
$correctSplitCheck out Split String by Tab Character in PowerShell
Practical Applications and Performance Considerations
As a PowerShell developer, it is essential to understand the performance considerations. All these are based on my experience working with this.
When to Use Each Method
- Use
-splitfor simple, readable code in most scenarios - Use
.Split()when you need to split by multiple delimiters - Use
ConvertFrom-Csvfor tabular data that follows CSV conventions - Use regex-based splitting for complex data with special requirements
Performance Comparison
For large datasets, performance can matter. Here’s a quick comparison:
$largeString = ("item1;item2;item3;" * 10000)
$time1 = Measure-Command { $largeString -split ";" }
$time2 = Measure-Command { $largeString.Split(";") }
"Split operator: $($time1.TotalMilliseconds) ms"
"Split method: $($time2.TotalMilliseconds) ms"In my testing, the .Split() method is typically slightly faster for very large strings, but the difference is negligible for most everyday use cases.
Table: Method Comparison
| Method | Pros | Cons | Best For |
|---|---|---|---|
| -split operator | Simple syntax, PowerShell native | Less flexibility with options | Everyday scripting |
| .Split() method | More options, multiple delimiters | .NET syntax less familiar to some | Complex splitting requirements |
| ConvertFrom-Csv | Creates structured objects automatically | Only works with CSV-like data | Processing tabular data |
| Regex splitting | Handles complex patterns | More difficult to read/maintain | Special cases with complex patterns |
In this tutorial, I explained how to split a string by semicolon in PowerShell using different methods. I hope you found this article helpful. If you have any questions or suggestions, please leave them in the comments below.
You may also like the following tutorials:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.