Simplify Math with Administrative Constants
1. Problem
You want to work with common administrative numbers (that is, kilobytes, megabytes, and gigabytes) without having to remember or calculate those numbers.
2. Solution
Use PowerShell’s administrative constants (KB, MB, and GB) to help work with these common numbers.
Calculate the download time (in seconds) of a 10.18 megabyte file over a connection that gets 215 kilobytes [...]
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 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 [...]
Repeat Operations with Loops
1. Problem
You want to execute the same block of code more than once.
2. Solution
Use one of PowerShell’s looping statements (for, foreach, while, and do), or PowerShell’s Foreach-Object cmdlet to run a command or script block more than once. For a detailed description of these looping statements, see “Looping Statements” in . For example:
Code View: Scroll [...]
Display the Properties of an Item As a List
1. Problem
You have an item (for example, an error record, directory item, or .NET object), and you want to display detailed information about that object in a list format.
2. Solution
To display detailed information about an item, pass that item to the Format-List cmdlet. For example, to display an error in list format, type the commands:
       [...]
Find a Command to Accomplish a Task
1. Problem
You want to accomplish a task in PowerShell but don’t know the command or cmdlet to accomplish that task.
2. Solution
Use the Get-Command cmdlet to search for and investigate commands.
To get the summary information about a specific command, specify the command name as an argument:
       Get-Command CommandName
To get the detailed information about a specific command, [...]
Customize Your Shell, Profile, and Prompt
1. Problem
You want to customize PowerShell’s interactive experience with a personalized prompt, aliases, and more.
2. Solution
When you want to customize aspects of PowerShell, place those customizations in your personal profile script. PowerShell provides easy access to this profile script by storing its location in the $profile variable.
By default, PowerShell’s security policies [...]

