How to split a string by delimiter in PowerShell?

Here is an example of splitting strings by a delimiter.

  • First, we are setting a variable $days with values with a comma as delimiter.
  • Then, splitting the variable by defining comma as a delimiter.
PS C:\Users\codetryout> $days = "Sun,Mon,Tue,Wed,Thu,Fri,Sat"
PS C:\Users\codetryout> $days -split ","
Sun
Mon
Tue
Wed
Thu
Fri
Sat
PS C:\Users\codetryout>

Note: This is tested in Windows 10, Powershell version: 5.1