PowerShell's -split operator divides text at a separator and puts the pieces in an array, a list you can read item by item. For a comma-separated value, use $parts = 'red,green,blue' -split ','; then $parts[0] gives you the first piece.
Unexpected results usually come from the separator: -split reads it as a regular expression, a pattern with special characters. A dot or pipe needs different handling from an ordinary comma.
In this guide
Start with one string and the separator you can see
Open Windows PowerShell, or choose the PowerShell profile inside Windows Terminal. Splitting text doesn't require an administrator account. Make sure the tab is running PowerShell rather than Command Prompt before entering the examples.
Run this small example first. It only creates variables in the current session and prints their values; it doesn't change a file:
$parts = 'red,green,blue' -split ','
$parts
The output is three separate entries: red, green, and blue. PowerShell displays array entries on separate lines, even though you started with one line of text. That's how PowerShell shows results; it hasn't changed your original document.

Microsoft's split operator reference explains how separators and result limits work. These basic examples work in Windows PowerShell 5.1 and PowerShell 7.
Replace the sample text with a short entry from your data showing what you need to split. Pick something with the actual separator you need, such as a colon in a label or a semicolon between fields. Don't start by modifying an entire file.
If pasting changes the command or runs it too early, check the PowerShell paste controls. Keep the quotes around the string and separator so PowerShell reads both as text.
Read individual pieces and limit the split
The result is an array, a collection of separate values. PowerShell counts its positions from zero. With the color example, $parts[0] is red, $parts[1] is green, and $parts[2] is blue. $parts.Count reports three.
Use a result limit when you want to split only the opening fields. For example, a label and a description may be separated by a colon, while the description itself contains another colon:
$parts = 'Topic: meeting starts at 09:30' -split ':', 2
$parts[0]
$parts[1]
This returns Topic as the first piece and the rest of the text, including the time's colon, as the second. The limit counts resulting pieces, not the number of separator characters to remove.
Without that limit, every matching colon splits the string. If a description appears cut short later in your script, check every entry in the array before assuming text has vanished. The remaining text may be in another position.
A limit of 0 means return all pieces. Negative limits, which split from the end, require PowerShell 7 or later. Avoid using a negative limit in a script that still needs to run in Windows PowerShell 5.1.
Escape dots, pipes, and other pattern characters
The separator for -split is normally a regular expression. That means a dot represents any character, and a pipe separates alternative patterns. Neither acts like a printed character until you tell PowerShell to match the character itself.
For a literal dot, put a backslash before it in the pattern:
'alpha.beta.gamma' -split '\.'
For a literal pipe, use the same approach:
'alpha|beta|gamma' -split '\|'
Each command returns alpha, beta, and gamma as separate entries. The backslash belongs to the separator pattern, not the original text. Keep it inside the quotes shown in the example.
For a separator stored in a variable, use [regex]::Escape so PowerShell matches any special characters in that value as ordinary text:
$separator = '|'
$text = 'alpha|beta|gamma'
$parts = $text -split [regex]::Escape($separator)
I'd use that form when a separator comes from a setting or user entry. It prevents a later change from a comma to a pipe from silently changing how the split works.
Another supported choice is the SimpleMatch option: 'alpha.beta' -split '.', 0, 'SimpleMatch'. The zero occupies the result-limit position; the option follows it. Use one approach consistently so the script stays easy to read.
Handle spaces and letter case precisely
For words separated by spaces, tabs, or newlines, use -split $text, without adding a separator. Its default separator handles spaces, tabs, and newlines, which is useful when the spacing isn't uniform.
For comma-separated entries with surrounding spaces, you can include those spaces in the separator pattern:
$parts = 'red, green, blue' -split '\s*,\s*'
The \s* parts match any amount of whitespace, such as spaces or tabs, around the comma. They don't remove spaces inside a value, so a multiword name stays together unless it contains the separator itself.
By default, -split ignores letter case when matching a separator. Use -csplit when uppercase and lowercase should match differently. For example, 'aXbxc' -csplit 'X' splits only at the uppercase X.
Keep empty fields when they mean missing data. Splitting 'red,,blue' at commas includes an empty middle entry. Removing it changes later positions, so a column-based script can start reading the wrong field.
Use a CSV parser when separators can appear inside values
Splitting on commas isn't a full CSV reader. A CSV field can contain a comma inside quotes, and a plain split doesn't recognize those quotes as part of the CSV format. A name or address with a comma can become two pieces by mistake.
For CSV text, use ConvertFrom-Csv with the correct headers. For a CSV file, use Import-Csv. These commands understand the format rather than treating each comma as a boundary even when it's inside a quoted value.
Keep the original input while checking the result, especially before saving the changed data back to a file. The PowerShell output-file guide explains saving output separately when the processed values are ready to save.
For an unexpected result, check the separator, result count, and PowerShell version. If someone else maintains the script, send them a made-up sample, your command, and the pieces you expected. Keep private source data out of that example.
The Short Version
Use -split with a quoted separator and read the array starting at position zero. Escape special characters when the separator must match literally. Set a result limit to preserve the remaining text, and parse quoted CSV with a CSV command.
Checked December 4, 2026.







