Computer Library windows 2008 exchange server power shell security register

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


Use a COM Object

1. Problem
You want to create a COM object to interact with its methods and properties.
2. Solution
Use the New-Object cmdlet (with the –ComObject parameter) to create a COM object from its ProgID. You can then interact with the methods and properties of the COM object as you would any other object in PowerShell.
        $object = New-Object [...]


Create an Instance of a .NET Object

1. Problem
You want to create an instance of a .NET object to interact with its methods and properties.
2. Solution
Use the New-Object cmdlet to create an instance of an object.
To create an instance of an object using its default constructor, use the New-Object cmdlet with the class name as its only parameter:
        PS >$generator = New-Object [...]


Work with .NET Objects

1. Problem
You want to use and interact with one of the features that make PowerShell so powerful—its intrinsic support for .NET objects.
2. Solution
PowerShell offers ways to access methods (both static and instance) and properties.
To call a static method on a class, place the type name in square brackets, and then separate the class name from [...]