Computer Library windows 2008 exchange server power shell security register

Search a String for Text or a Pattern

1. Problem
You want to determine if a string contains another string, or want to find the position of a string within another string.
2. Solution
PowerShell provides several options to help you search a string for text.
Use the –like operator to determine whether a string matches a given DOS-like wildcard:
        PS >”Hello World” -like “*llo W*”
        True
[...]


Place Formatted Information in a String

1. Problem
You want to place formatted information (such as right-aligned text or numbers rounded to a specific number of decimal places) in a string.
2. Solution
Use PowerShell’s formatting operator to place formatted information inside a string.
        PS >$formatString = “{0,8:D4} {1:C}’n”
        PS >$report = “Quantity Price’n”
        PS >$report += “—————’n”
        PS >$report += $formatString -f 50,2.5677
        [...]


Insert Dynamic Information in a String

1. Problem
You want to place dynamic information (such as the value of another variable) in a string.
2. Solution
In an expanding string, include the name of a variable in the string to insert the value of that variable.
        PS >$header = “Report for Today”
        PS >$myString = “$header’n—————-”
        PS >$myString
        Report for Today
        —————-

To include [...]


Place Special Characters in a String

1. Problem
You want to place special characters (such as tab and newline) in a string variable.
2. Solution
In an expanding string, use PowerShell’s escape sequences to include special characters such as tab and newline.
        PS >$myString = “Report for Today’n—————-”
        PS >$myString
        Report for Today
        —————-

3. Discussion
As discussed in Section 5.1, “Create a String,” PowerShell strings [...]


Create a String

1. Problem
You want to create a variable that holds text.
2. Solution
Use PowerShell string variables to give you a way to store and work with text.
To define a string that supports variable expansion and escape characters in its definition, surround it with double quotes:
        $myString = “Hello World”

To define a literal string (that does not [...]