Computer Library windows 2008 exchange server power shell security register

Control Access and Scope of Variables and Other Items

1. Problem
You want to control how you define (or interact with) the visibility of variables, aliases, functions, and drives.
2. Solution
PowerShell offers several ways to access variables.
To create a variable with a specific scope, supply that scope before the variable name:
        $SCOPE:variable = value

To access a variable at a specific scope, supply that scope before [...]


Access Environment Variables

1. Problem
You want to use an environment variable (such as the system path, or current user’s name) in your script or interactive session.
2. Solution
PowerShell offers several ways to access environment variables.
To list all environment variables, list the children of the env drive:
        Get-ChildItem env:

To get an environment variable using a more concise syntax, precede [...]


Configure Debug, Verbose, and Progress Output

1. Problem
You want to manage the detailed debug, verbose, and progress output generated by cmdlets and scripts.
2. Solution
To enable debug output for scripts and cmdlets that generate it:
       
        $debugPreference = “Continue”
        Start-DebugCommand

To enable verbose mode for a cmdlet that checks for the -Verbose parameter:
        Copy-Item c:\temp\*.txt c:\temp\backup\ -Verbose

To disable progress output from a script [...]


Access and Manage Your Console History

1. Problem
After working in the shell for a while, you want to invoke commands from your history, view your command history, and save your command history.
2. Solution
The shortcuts given in Section 1.12, “Customize the Shell to Improve Your Productivity” let you manage your history, but PowerShell offers several features to help you work with your [...]