A string is a sequence of characters used for text data. In PowerShell, a string is a System.String object, so it can be stored in variables, inspected, passed to parameters, and manipulated with methods or operators. section 3.5.4 section 16.2
Use strings in several common administration tasks:
- Quote a string when it contains spaces. Single and double quotation marks are accepted, although single quotes are recommended for ordinary strings. section 3.5.4
- Supply one or more strings to parameters. A String[] parameter accepts an array, and comma-separated values create an array; quote only individual values containing spaces. section 3.5.4
- Inspect a string with Get-Member, then call methods such as IndexOf(), ToLower(), ToUpper(), Trim(), TrimStart(), and TrimEnd(). section 26.3
- Convert between arrays and delimited strings with -join and -split. Use a delimiter such as a pipe or the tab escape sequence `t. section 26.2.3
- Check the type of pipeline data before passing it to a string parameter. Extract a string property from an object when the command produces objects instead of String values. section 10.8
Clean and split administrator data
$username = " Sarah " $username.Trim() # Sarah $array = "one","two","three" $string = $array -join "|" # one|two|three $array = ($string -split "|") $array[0] # one
Avoid confusing strings with numbers
Read-Host returns a string. Multiplying the entered value "100" by 10 repeats the text rather than performing numeric multiplication. Declare the variable as [int] when numeric input is required; PowerShell then converts valid input and reports an error for values such as "Hello". section 16.6
-Filter <String>
Specifies a filter in the format or language of the provider.
The value of this parameter qualifies the Path parameter.
The syntax of the filter, including the use of wildcard characters,
depends on the provider. Filters are more efficient than
other parameters, because the provider applies them when the cmdlet
gets the objects rather than having PowerShell filter
the objects after they are retrieved.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? true
Use the parameter listing to see how a String filter is accepted, interpreted by the provider, and applied to a path. section 3.5.4























