โšกPowerShellWiki
โ† All cheat sheets
๐Ÿ”ค

Strings & Text

Manipulate strings, match patterns, and format output.

Transforming strings

Replace text

Substitute one substring for another.

"Hello World" -replace "World", "PowerShell"

Split a string

Break a string into an array on a delimiter.

"a,b,c" -split ","

Join an array into a string

Combine array elements with a separator.

@("a", "b", "c") -join " | "

Trim and change case

Clean up whitespace and normalize case.

"  Hello  ".Trim().ToUpper()

Searching and matching

Search files for a pattern (grep)

Find lines matching a regex across files.

Select-String -Path ".\*.log" -Pattern "ERROR"

Test a regex match

Return true/false if a string matches.

"user@example.com" -match "^[^@]+@[^@]+\.[^@]+$"

Extract with a capture group

Pull a value out using $matches.

if ("Order #4521" -match "#(\d+)") { $matches[1] }

Formatting output

Format with placeholders

Insert values into a template string.

"{0} has {1} items" -f "Cart", 3

Pad and align numbers

Right-align a number in a fixed width.

"{0,8:N2}" -f 1234.5

Related cheat sheets