Computer Library windows 2008 exchange server power shell security register

Work with Numbers As Binary

1. Problem
You want to work with the individual bits of a number, or work with a number built by combining a series of flags.
2. Solution
To directly enter a hexadecimal number, use the 0x prefix:
        PS >$hexNumber = 0×1234
        PS >$hexNumber
        4660

To convert a number to its binary representation, supply a base of 2 to the [...]


Perform Complex Arithmetic

1. Problem
You want to use PowerShell to calculate more complex or advanced mathematical results.
2. Solution
PowerShell supports more advanced mathematical tasks primarily through its support for the System.Math class in the .NET Framework.
To find the absolute value of a number, use the [Math]::Abs() method:
        PS >[Math]::Abs(-10.6)
        10.6

To find the power (such as the square or the [...]


Format a Date for Output

1. Problem
You want to control the way that PowerShell displays or formats a date.
2. Solution
To control the format of a date, use one of the following options:
The Get-Date cmdlet’s –Format parameter:
PS >Get-Date -Date “05/09/1998 1:23 PM” -Format “dd-MM-yyyy @ hh:mm:ss”
09-05-1998 @ 01:23:00
PowerShell’s string formatting (–f) operator:
PS >$date = [DateTime] “05/09/1998 1:23 PM”
PS >”{0:dd-MM-yyyy @ hh:mm:ss}” [...]


Convert a String to Upper/Lowercase

1. Problem
You want to convert a string to uppercase or lowercase.
2. Solution
Use the ToUpper() and ToLower() methods of the string to convert it to uppercase and lowercase, respectively.
To convert a string to uppercase, use the ToUpper() method:
        PS >”Hello World”.ToUpper()
        HELLO WORLD

To convert a string to lowercase, use the ToLower() method:
        PS >”Hello World”.ToLower()
        [...]


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 [...]


Make Decisions with Comparison and Logical Operators

1. Problem
You want to compare some data with other data and make a decision based on that comparison.
2. Solution
Use PowerShell’s logical operators to compare pieces of data and make decisions based on them.

Comparison operators:
-eq, -ne, -ge, -gt, -lt, -le, -like, -notlike, -match, -notmatch, -contains, -notcontains, -is, -isnot

Logical operators:
-and, -or, -xor, -not
For a detailed [...]


Add Custom Methods and Properties to Objects

1. Problem
You have an object and want to add your own custom properties or methods (members) to that object.
2. Solution
Use the Add-Member cmdlet to add custom members to an object.
3. Discussion
The Add-Member cmdlet is extremely useful in helping you add custom members to individual objects. For example, imagine that you want to create a report [...]


Types and Objects

1. Problem
You have an instance of an object and want to know what methods and properties it supports.
2. Solution
The most common way to explore the methods and properties supported by an object is through the Get-Member cmdlet.
To get the instance members of an object you’ve stored in the $object variable, pipe it to the Get-Member [...]


Work with Each Item in a List or Command Output

1. Problem
You have a list of items and want to work with each item in that list.
2. Solution
Use the Foreach-Object cmdlet (which has the standard aliases foreach and %)to work with each item in a list.
To apply a calculation to each item in a list, use the $_ variable as part of a calculation in [...]