powershell string split is the operator and method in PowerShell to split one or more strings into substrings based on a delimiter, regex pattern, or script block.
$string = "The best PowerShell blog" $string -split " " # Result The best PowerShell blog
Syntax
# Binary -split operator
-Split <String[]> [-Delimiter <String>] [-MaxSubstrings <Int32>] [-ScriptBlock <ScriptBlock>] [-Options <SplitOptions>]
# Unary -split operator (splits on whitespace)
-Split <String>
# .Split() method (string)
$string.Split($delimiter[, $count, $options])
Options and Flags
| Parameter | Type | Default | Description |
|---|---|---|---|
-Delimiter |
String | Whitespace | One or more characters to split on. Supports regex when using -split. |
-MaxSubstrings |
Int32 | All substrings | Maximum number of substrings returned. Negative values count from the end (PowerShell 7+). |
-ScriptBlock |
ScriptBlock | N/A | Expression evaluated per substring to determine splitting (advanced). |
-Options |
SplitOptions | None | Use SimpleMatch for literal delimiter, or RegexMatch (default) with IgnoreCase. |
.Split() count |
Int32 | All | Number of substrings to return; 0 returns original string. |
.Split() options |
System.StringSplitOptions | None | RemoveEmptyEntries or TrimEntries (.NET). |
Usage Examples
Split a CSV line into array
$string = "apple,banana,cherry,date"
$string.split(',').trim()
# Output: apple banana cherry date
Extract last segment from hyphen-delimited string
$string = "Delivery-contract-20230401"
$splitArray = $string.Split("-")
$splitArray[-1] # Result: 20230401
Split on multiple delimiters with regex
$string = "Hello123World456Test789"
$string -split "d+" # Result: Hello World Test
Limit substrings to three fragments
'Chocolate-Vanilla-Strawberry-Blueberry' -split '(-)', 3
# Result: Chocolate - Vanilla - Strawberry-Blueberry
Split on multiple spaces or tabs
$string = "This is a string with multiple spaces and tabs"
$string -split "s+"
Split on sentences
$string = "This is a sentence. And here is another one! Finally, a third sentence."
$string -split "[.!?]"
Frequently Asked Questions
What is the difference between the -split operator and the .Split() method in PowerShell?
Answer: The -split operator uses regex delimiters by default; .Split() treats the delimiter literally, without regex interpretation. For example, "a b c" -split 's+' splits on one or more spaces, while "a,b,c".Split(',') splits on commas only.
When should I use the -SimpleMatch flag with -split?
Answer: Use -SimpleMatch to force literal delimiter parsing, avoiding regex special characters. For example, "file.name.log" -split '.' -SimpleMatch splits on literal dots, not the regex wildcard.
How do I fix “Cannot index into a null array” when splitting an empty string?
Answer: Splitting a null or empty string with -split returns $null, not an empty array. Use the null-conditional operator (PowerShell 7+): $parts = $string?.Split(',') ?? @(). For PowerShell 5.1, wrap with an if block.
Does the -split operator work on PowerShell Core (Linux/macOS) as well as Windows?
Answer: Yes, -split is fully cross-platform in PowerShell 6+ (PowerShell Core). Same syntax works on any platform, e.g., splitting $env:PATH on colon or semicolon.
What is the fastest way to split a large string in PowerShell?
Answer: For large strings, the -split operator is generally faster than .Split() when using a simple regex delimiter. Use Measure-Command to benchmark your specific scenario.

Command Line Expert & Software Engineer
Welcome! I’m Thomas Heinrich, a software engineer and system administrator with a deep passion for the Command Line Interface (CLI). With years of experience navigating the terminal, building backend architectures, and automating server deployments, I created this space to share practical, real-world terminal knowledge.
Whether you are a beginner taking your first steps in a Linux environment or a seasoned DevOps engineer looking to optimize your deployment scripts, you will find actionable solutions here. My goal is to help you ditch the mouse, speed up your workflow, and harness the full power of the command line.