Tag Archives: Option

Trace-Command

NAME
    Trace-Command

SYNOPSIS
    Configures and starts a trace of the specified expression or command.

SYNTAX
    Trace-Command [-Command] <string> [-ArgumentList <Object[]>] [-Name] <string[]> [[-Option] {None | Constructor | Dispose | Finalizer | Method | Property | Delegates | Events | Exception | Lock | Error | Errors | Warning | Verbose | WriteLine | Data | Scope | ExecutionFlow | Assert | All}] [-Debugger] [-FilePath <string>] [-Force] [-InputObject <psobject>] [-ListenerOption {None | LogicalOperationStack | DateTime | Timestamp | ProcessId | ThreadId | Callstack}] [-PSHost] [<CommonParameters>]

    Trace-Command [-Expression] <scriptblock> [-Name] <string[]> [[-Option] {None | Constructor | Dispose | Finalizer | Method | Property | Delegates | Events | Exception | Lock | Error | Errors | Warning | Verbose | WriteLine | Data | Scope | ExecutionFlow | Assert | All}] [-Debugger] [-FilePath <string>] [-Force] [-InputObject <psobject>] [-ListenerOption {None | LogicalOperationStack | DateTime | Timestamp | ProcessId | ThreadId | Callstack}] [-PSHost] [<CommonParameters>]

DESCRIPTION
    The Trace-Command cmdlet configures and starts a trace of the specified expression or command. It works like Set-TraceSource, except that it applies only to the specified command.

PARAMETERS
    -ArgumentList <Object[]>
        Specifies the parameters and parameter values for the command being traced. The Alias for ArgumentList is Args. This feature is especially useful for debugging dynamic parameters.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Command <string>
        Specifies a command that is being processed during the trace.

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Debugger [<SwitchParameter>]
        Sends the trace output to the debugger. You can view the output in any user-mode or kernel mode debugger or in Visual Studio. This parameter also selects the default trace listener.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Expression <scriptblock>
        Specifies the expression that is being processed during the trace. Enclose the expression in curly braces ({}).

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -FilePath <string>
        Sends the trace output to the specified file. This parameter also selects the file trace listener.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Allows the cmdlet to append trace information to a read-only file. Used with the FilePath parameter. Even using the Force parameter, the cmdlet cannot override security restrictions.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Provides input to the expression that is being processed during the trace.

        You can enter a Variable that represents the input that the expression accepts, or pass an object through the pipeline.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -ListenerOption <TraceOptions>
        Adds optional data to the prefix of each trace message in the output. The valid values are None, LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, and Callstack. “None” is the default.

        To specify multiple options, separate them with commas, but with no spaces, and enclose them in quotation marks, such as “ProcessID,ThreadID”.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Name <string[]>
        Determines which Windows PowerShell components are traced. Enter the name of the trace source of each component. Wildcards are permitted. To find the trace sources on your computer, type “Get-TraceSource“.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Option <PSTraceSourceOptions>
        Determines the type of events that are traced.

        The valid values are None, Constructor, Dispose, Finalizer, Method, Property, Delegates, Events, Exception, Lock, Error, Errors, Warning, Verbose, WriteLine, Data, Scope, ExecutionFlow, Assert, and All. “All” is the default.

        The following values are combinations of other values:

        — ExecutionFlow: (Constructor, Dispose, Finalizer, Method, Delegates, Events, and Scope)

        — Data: (Constructor, Dispose, Finalizer, Property, Verbose, and WriteLine)

        — Errors: (Error and Exception).

        To specify multiple options, separate them with commas, but with no spaces, and enclose them in quotation marks, such as “Constructor,Dispose”.

        Required?                    false
        Position?                    3
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PSHost [<SwitchParameter>]
        Sends the trace output to the Windows PowerShell host. This parameter also selects the PSHost trace listener.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe objects that represent input to the expression to Trace-Command.

OUTPUTS
    System.Management.Automation.PSObject
        Returns the command trace in the debug stream.

NOTES

        Tracing is a method that developers use to debug and refine programs. When tracing, the program generates detailed messages about each step in its internal processing.

        The Windows PowerShell tracing cmdlets are designed to help Windows PowerShell developers, but they are available to all users. They let you monitor nearly every aspect of the Functionality of the shell.

        To find the Windows PowerShell components that are enabled for tracing, type “Get-Help Get-TraceSource.”

        A “trace source” is the part of each Windows PowerShell component that manages tracing and generates trace messages for the component. To trace a component, you identify its trace source.

        A “trace listener” receives the output of the trace and displays it to the user. You can elect to send the trace data to a user-mode or kernel-mode debugger, to the host or console, to a file, or to a custom listener derived from the System.Diagnostics.TraceListener class.

        When you use the Command parameter set, Windows PowerShell processes the command just as it would be processed in a pipeline. For example, command discovery is not repeated for each incoming object.

        The names of the Name, Expression, Option, and Command parameters are optional. If you omit the parameter names, the unnamed parameter values must appear in this order: Name, Expression, Option or Name, Command,-Option . If you include the parameter names, the parameters can appear in any order.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {Get-Process notepad} -PSHost

    Description
    ———–
    This command starts a trace of metadata processing, parameter binding, and cmdlet creation and destruction of the “Get-Process notepad” expression. It uses the Name parameter to specify the trace sources, the Expression parameter to specify the command, and the PSHost parameter to send the output to the console. Because it does not specify any tracing options or listener options, the command uses the defaults, “All” for the tracing options, and “None” for the listener options.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Trace-Command -Name commandprocessor,pipelineprocessor -command Get-Alias -argumentlist “ghy” -Option executionflow -ListenerOption “timestamp,callstack” -FilePath c:\test\debug.txt

    Description
    ———–
    This command starts a trace of the command processor and pipeline processor while processing the “Get-Alias cd” command.

    It uses the Name parameter to specify the trace sources, the Command parameter to specify the command, the ArgumentList parameter to specify the parameters of the Get-Alias command, the Option parameter to specify tracing options, and the ListenerOption parameter to specify the fields in the trace message prefix. The FilePath parameter sends the output to the C:\Test\Debug.txt file.

    ————————– EXAMPLE 3 ————————–

    C:\PS>$a = “i*”

    C:\PS> Trace-Command parameterbinding {Get-Alias $input} -PSHost -InputObject $a

    Description
    ———–
    These commands trace the actions of the ParameterBinding operations of Windows PowerShell while it processes a Get-Alias expression that takes input from the pipeline.

    In Trace-Command, the InputObject parameter passes an object to the expression that is being processed during the trace.

    The first command stores the string “i*” in the $a Variable. The second command uses the Trace-Command cmdlet with the ParameterBinding trace source. The PSHost parameter sends the output to the console.

    The expression being processed is “Get-Alias $input”, where the $input Variable is associated with the InputObject parameter. The InputObject parameter passes the Variable $a to the expression. In effect, the command being processed during the trace is “Get-Alias -InputObject $a” or “$a | Get-Alias“.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113419
    Get-TraceSource
    Set-TraceSource

Set-Variable

NAME
    Set-Variable

SYNOPSIS
    Sets the value of a Variable. Creates the Variable if one with the requested name does not exist.

SYNTAX
    Set-Variable [-Name] <string[]> [[-Value] <Object>] [-Description <string>] [-Exclude <string[]>] [-Force] [-Include <string[]>] [-Option {None | ReadOnly | Constant | Private | AllScope}] [-PassThru] [-Scope <string>] [-Visibility {Public | Private}] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Set-Variable cmdlet assigns a value to a specified Variable or changes the current value. If the Variable does not exist, the cmdlet creates it.

PARAMETERS
    -Description <string>
        Specifies the description of the Variable.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Allows you to create a Variable with the same name as an existing read-only Variable, or to change the value of a read-only Variable.

        By default, you can overwrite a Variable, unless the Variable has an option value of “ReadOnly” or “Constant”. For more information, see the Option parameter.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Include <string[]>
        Changes only the specified items. The value of this parameter qualifies the Name parameter. Enter a name or name pattern, such as “c*”. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Name <string[]>
        Specifies the Variable name.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Option <ScopedItemOptions>
        Changes the value of the Options property of the Variable. Valid values are:

        — None: Sets no options. (“None” is the default.)

        — ReadOnly: The properties of the Variable cannot be changed, except by using the Force parameter. You can use Remove-Variable to delete the Variable.

        — Constant: The Variable cannot be deleted and its properties cannot be changed. “Constant” is available only when you are creating an Alias. You cannot change the option of an existing Variable to “Constant”.

        — Private: The Variable is available only within the scope specified by the Scope parameter. It is inherited by child scopes.

        — AllScope: The Variable is copied to any new scopes that are created.

        To see the Options property of the Variables, type “Get-Variable| Format-Table -property name, options -autosize”.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns an object representing the new Variable. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Scope <string>
        Determines the scope of the Variable. Valid values are “Global”, “Local”, or “Script”, or a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). “Local” is the default. For more information, see about_scopes.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Value <Object>
        Specifies the value of the Variable.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -Visibility <SessionStateEntryVisibility>
        Determines whether the Variable is visible outside of the session in which it was created. This parameter is designed for use in scripts and commands that will be delivered to other users.

        Valid values are:

        — Public: The Variable is visible. (“Public” is the default.)
        — Private: The Variable is not visible.

        When a Variable is private, it does not appear in lists of Variables, such as those returned by Get-Variable, or in displays of the Variable: drive. Commands to read or change the value of a private Variable return an error. However, the user can run commands that use a private Variable if the commands were written in the session in which the Variable was defined.

        Required?                    false
        Position?                    named
        Default value                Public
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Object
        You can pipe an object that represents the value of the Variable to Set-Variable.

OUTPUTS
    None or System.Management.Automation.PSVariable
        When you use the PassThru parameter, Set-Variable generates a System.Management.Automation.PSVariable object representing the new or changed Variable. Otherwise, this cmdlet does not generate any output.

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>Set-Variable -Name desc -Value “A description”

    C:\PS>Get-Variable -Name desc

    Description
    ———–
    These commands set the value of the “desc” Variable to “A description”, and then get the value of the Variable.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Set-Variable -Name processes -Value (Get-Process) -Option constant -Scope global -Description “All processes” -PassThru | Format-List -property *

    Description
    ———–
    This command creates a global, read-only Variable that contains all processes on the system, and then it displays all properties of the Variable.

    The command uses the Set-Variable cmdlet to create the Variable. It uses the PassThru parameter to create an object representing the new Variable, and it uses the pipeline operator (|) to pass the object to the Format-List cmdlet. It uses the Property parameter of Format-List with a value of all (*) to display all properties of the newly created Variable.

    The value, “(Get-Process)”, is enclosed in parentheses to ensure that it is executed before being stored in the Variable. Otherwise, the Variable contains the words “Get-Process“.

    ————————– EXAMPLE 3 ————————–

    C:\PS># Set-Variable -Name counter -Visibility private

    C:\PS> New-Variable -Name counter -Visibility public -Value 26

    C:\PS> $counter
    26

    C:\PS> Get-Variable c*

    Name Value
    —- —–
    Culture en-US
    ConsoleFileName
    ConfirmPreference High
    CommandLineParameters {}
    Counter 26

    C:\PS> Set-Variable -Name counter -Visibility private

    C:\PS> Get-Variable c*

    Name Value
    —- —–
    Culture en-US
    ConsoleFileName
    ConfirmPreference High
    CommandLineParameters {}

    C:\PS> $counter
    “Cannot access the Variable ‘$counter’ because it is a private Variable

    C:\PS> .\use-counter.ps1
    Commands completed successfully.

    Description
    ———–
    This command shows how to change the visibility of a Variable to “Private”. This Variable can be read and changed by scripts with the required permissions, but it is not visible to the user.

    The sample output shows the difference in the behavior of public and private Variables.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113401
    Get-Variable
    New-Variable
    Remove-Variable
    Clear-Variable

Set-Alias

NAME
    Set-Alias

SYNOPSIS
    Creates or changes an Alias (alternate name) for a cmdlet or other command element in the current Windows PowerShell session.

SYNTAX
    Set-Alias [-Name] <string> [-Value] <string> [-Description <string>] [-Force] [-Option {None | ReadOnly | Constant | Private | AllScope}] [-PassThru] [-Scope <string>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Set-Alias cmdlet creates or changes an Alias (alternate name) for a cmdlet or for a command element, such as a Function, a script, a file, or other executable. You can also use Set-Alias to reassign a current Alias to a new command, or to change any of the properties of an Alias, such as its description. Unless you add the Alias to the Windows PowerShell profile, the changes to an Alias are lost when you exit the session or close Windows PowerShell.

PARAMETERS
    -Description <string>
        Specifies a description of the Alias. You can type any string. If the description includes spaces, enclose it quotation marks.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Allows the cmdlet to set a read-only Alias. Use the Option parameter to create a read-only Alias. The Force parameter cannot set a constant Alias.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Name <string>
        Specifies the new Alias. You can use any alphanumeric characters in an Alias, but the first character cannot be a number.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Option <ScopedItemOptions>
        Sets the value of the Options property of the Alias.

        Valid values are:

        — None: Sets no options. (default)

        — ReadOnly: The properties of the Alias cannot be changed, except by using the Force parameter. You can use Remove-Item to delete the Alias.

        — Constant: The Alias cannot be deleted and its properties cannot be changed. Constant is available only when you are creating an Alias. You cannot change the option of an existing Alias to Constant.

        — Private: The Alias is available only within the scope specified by the Scope parameter. It is invisible in all other scopes.

        — AllScope: The Alias is copied to any new scopes that are created.

        To see the Options property of the Aliases, type “Get-Alias | Format-Table -property Name, Definition, Options -autosize”.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns an object representing the Alias. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Scope <string>
        Specifies the scope in which this Alias is valid. Valid values are “Global”, “Local”, or “Script”, or a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). “Local” is the default. For more information, see about_scopes.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Value <string>
        Specifies the name of the cmdlet or command element that is being Aliased.

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to this cmdlet.

OUTPUTS
    None or System.Management.Automation.AliasInfo
        When you use the PassThru parameter, Set-Alias generates a System.Management.Automation.AliasInfo object representing the Alias. Otherwise, this cmdlet does not generate any output.

NOTES

        An Alias is an alternate name or nickname for a cmdlet or command element. To run the cmdlet, you can use its full name or any valid Alias. For more information, see about_aliases.

        To create a new Alias, use Set-Alias or New-Alias. To delete an Alias, use Remove-Item.

        A cmdlet can have multiple Aliases, but an Alias can only be associated with one cmdlet at a time. If you use Set-Alias to associate the Alias with a different cmdlet, it is no longer associated with the original cmdlet.

        You can create an Alias for a cmdlet, but you cannot create an Alias for a command with parameters and values. For example, you can create an Alias for Set-Location, but you cannot create an Alias for “Set-Location C:\Windows\System32″. To create an Alias for a command, create a Function that includes the command, and then create an Alias to the Function.

        To save the Aliases from a session and use them in a different session, add the Set-Alias command to your Windows PowerShell profile. Profiles do not exist by default. To create a profile in the path stored in the $profile Variable, type “New-Item -type file -Force $profile”. To see the value of the $profile Variable, type “$profile”.

        You can also save your Aliases by using Export-Alias to copy the Aliases from the session to a file, and then use Import-Alias to add them to the Alias list for a new session.

        You can also refer to Set-Alias by its built-in Alias, “sal”. For more information, see about_aliases.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Set-Alias -Name list -Value Get-ChildItem

    Description
    ———–
    This command creates the Alias “list” for the Get-ChildItem cmdlet. After you create the Alias, you can use “list” in place of “Get-ChildItem” at the command line and in scripts.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Set-Alias list Get-Location

    Description
    ———–
    This command associates the Alias “list” with the Get-Location cmdlet. If “list” is an Alias for another cmdlet, this command changes its association so that it now is the Alias only for Get-Location.

    This command uses the same format as the command in the previous example, but it omits the optional parameter names, -Name and -Value. When you omit parameter names, the values of those parameters must appear in the specified order in the command. In this case, the value of -Name (“list”) must be the first parameter and the value of -Value (“Get-Location“) must be the second parameter.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Set-Alias scrub Remove-Item -Option readonly -PassThru | Format-List

    Description
    ———–
    This command associates the Alias “scrub” with the Remove-Item cmdlet. It uses the “ReadOnly” option to prevent the Alias from being deleted or assigned to another cmdlet.

    The PassThru parameter directs Windows PowerShell to pass an object that represents the new Alias through the pipeline to the Format-List cmdlet. If the PassThru parameter were omitted, there would be no output from this cmdlet to display (in a list or otherwise).

    ————————– EXAMPLE 4 ————————–

    C:\PS>Set-Alias np c:\windows\notepad.exe

    Description
    ———–
    This command associates the Alias, “np”, with the executable file for Notepad. After the command completes, to open Notepad from the Windows PowerShell command line, just type “np”.

    This example demonstrates that you can create Aliases for executable files and elements other than cmdlets.

    To make the command more generic, you can use the “Windir” Environment Variable (${env:windir}) to represent the C\Windows directory. The generic version of the command is “Set-Alias np ${env:windir}\notepad.exe”.

    ————————– EXAMPLE 5 ————————–

    C:\PS>function CD32 {Set-Location c:\windows\system32}

    C:\PS>Set-Alias go cd32

    Description
    ———–
    These commands show how to assign an Alias to a command with parameters, or even to a pipeline of many commands.

    You can create an Alias for a cmdlet, but you cannot create an Alias for a command that consists of a cmdlet and its parameters. However, if you place the command in a Function or a script, then you can create a useful Function or script name and you can create one or more Aliases for the Function or script.

    In this example, the user wants to create an Alias for the command “Set-Location c:\windows\system32″, where “Set-Location” is a cmdlet and “C:\Windows\System32” is the value of the Path parameter.

    To do this, the first command creates a Function called “CD32” that contains the Set-Location command.

    The second command creates the Alias “go” for the CD32 Function. Then, to run the Set-Location command, the user can type either “CD32” or “go”.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113390
    Get-Alias
    New-Alias
    Export-Alias
    Import-Alias

Set-TraceSource

NAME
    Set-TraceSource

SYNOPSIS
    Configures, starts, and stops a trace of Windows PowerShell components.

SYNTAX
    Set-TraceSource [[-Option] {None | Constructor | Dispose | Finalizer | Method | Property | Delegates | Events | Exception | Lock | Error | Errors | Warning | Verbose | WriteLine | Data | Scope | ExecutionFlow | Assert | All}] [-Debugger] [-FilePath <string>] [-Force] [-ListenerOption {None | LogicalOperationStack | DateTime | Timestamp | ProcessId | ThreadId | Callstack}] [-PassThru] [-PSHost] [-Name] <string[]> [<CommonParameters>]

    Set-TraceSource [-RemoveListener <string[]>] [-Name] <string[]> [<CommonParameters>]

    Set-TraceSource [-RemoveFileListener <string[]>] [-Name] <string[]> [<CommonParameters>]

DESCRIPTION
    The Set-TraceSource cmdlet configures, starts, and stops a trace of a Windows PowerShell component. You can use it to specify which components will be traced and where the tracing output is sent.

PARAMETERS
    -Debugger [<SwitchParameter>]
        Sends the trace output to the debugger. You can view the output in any user-mode or kernel mode debugger or in Microsoft Visual Studio. This parameter also selects the default trace listener.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -FilePath <string>
        Sends the trace output to the specified file. This parameter also selects the file trace listener. If you use this parameter to start the trace, use the RemoveFileListener parameter to stop the trace.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Allows the cmdlet to overwrite a read-only file. Use with the FilePath parameter.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -ListenerOption <TraceOptions>
        Adds optional data to the prefix of each trace message in the output. The valid values are “None”, “LogicalOperationStack”, “DateTime”, “Timestamp”, “ProcessId”, “ThreadId”, and “Callstack”. “None” is the default.

        To specify multiple options, separate them with commas, but with no spaces, and enclose them in quotation marks, such as “ProcessID,ThreadID”.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Name <string[]>
        Determines which components are traced. Enter the name of the trace source of each component. Wildcards are permitted.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -Option <PSTraceSourceOptions>
        Determines the type of events that are traced.

        The valid values are: “None”, “Constructor”, “Dispose”, “Finalizer”, “Method”, “Property”, “Delegates”, “Events”, “Exception”, “Lock”, “Error”, “Errors”, “Warning”, “Verbose”, “WriteLine”, “Data”, “Scope”, “ExecutionFlow”, “Assert”, and “All”. “All” is the default.

        The following values are combinations of other values:

        — ExecutionFlow: (Constructor, Dispose, Finalizer, Method, Delegates, Events, and Scope)

        — Data: (Constructor, Dispose, Finalizer, Property, Verbose, and WriteLine)

        — Errors: (Error and Exception).

        To specify multiple options, separate them with commas, but with no spaces, and enclose them in quotation marks, such as “Constructor,Dispose”.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns an object representing the trace session. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PSHost [<SwitchParameter>]
        Sends the trace output to the Windows PowerShell host. This parameter also selects the PSHost trace listener.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -RemoveFileListener <string[]>
        Stops the trace by removing the file trace listener associated with the specified file. Enter the path and file name of the trace output file.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -RemoveListener <string[]>
        Stops the trace by removing the trace listener.

        Use the following values with RemoveListener:

        –To remove PSHost (console), type “Host”.
        –To remove Debugger, type “Debug”.
        –To remove all trace listeners, type “*”.

        To remove the file trace listener, use the RemoveFileListener parameter.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe a string that contains a name to Set-TraceSource.

OUTPUTS
    None or System.Management.Automation.PSTraceSource
        When you use the PassThru parameter, Set-TraceSource generates a System.Management.Automation.PSTraceSource object representing the trace session. Otherwise, this cmdlet does not generate any output.

NOTES

        Tracing is a method that developers use to debug and refine programs. When tracing, the program generates detailed messages about each step in its internal processing.

        The Windows PowerShell tracing cmdlets are designed to help Windows PowerShell developers, but they are available to all users. They let you monitor nearly every aspect of the Functionality of Windows PowerShell.

        A “trace source” is the part of each Windows PowerShell component that manages tracing and generates trace messages for the component. To trace a component, you identify its trace source.

        A “trace listener” receives the output of the trace and displays it to the user. You can elect to send the trace data to a user-mode or kernel-mode debugger, to the console, to a file, or to a custom listener derived from the System.Diagnostics.TraceListener class.

        To start a trace, use the Name parameter to specify a trace source (the component to be traced) and the FilePath, Debugger, or PSHost parameters to specify a listener (a destination for the output). Use the Options parameter to determine the types of events that are traced and the ListenerOptions parameter to configure the trace output.

        To change the configuration of a trace, enter a Set-TraceSource command as you would to start a trace. Windows PowerShell recognizes that the trace source is already being traced. It stops the trace, adds the new configuration, and starts or restarts the trace.

        To stop a trace, use the RemoveListener parameter. To stop a trace that uses the file listener (a trace started by using the -FilePath parameter), use the RemoveFileListener parameter. When you remove the listener, the trace stops.

        To determine which components can be traced, use Get-TraceSource. The trace sources for each module are loaded automatically when the component is in use, and they appear in the output of Get-TraceSource.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Set-TraceSource -Name Parameterbinding -Option ExecutionFlow -PSHost
    -ListenerOption “ProcessID,TimeStamp”

    Description
    ———–
    This command starts tracing for the ParameterBinding component of Windows PowerShell. It uses the Name parameter to specify the trace source, the Option parameter to select the ExecutionFlow trace events, and the PSHost parameter to select the Windows PowerShell host listener, which sends the output to the console. The ListenerOption parameter adds the “ProcessID” and “TimeStamp” values to the trace message prefix.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Set-TraceSource -Name ParameterBinding -RemoveListener Host

    Description
    ———–
    This command stops the trace of the ParameterBinding component of Windows PowerShell. It uses the Name parameter to identify the component that was being traced and the RemoveListener parameter to identify the trace listener.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113400
    Get-TraceSource
    Trace-Command
    Set-PSDebug

New-Variable

NAME
    New-Variable

SYNOPSIS
    Creates a new Variable.

SYNTAX
    New-Variable [-Name] <string> [[-Value] <Object>] [-Description <string>] [-Force] [-Option {None | ReadOnly | Constant | Private | AllScope}] [-PassThru] [-Scope <string>] [-Visibility {Public | Private}] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The New-Variable cmdlet creates a new Variable in Windows PowerShell. You can assign a value to the Variable while creating it or assign or change the value after it is created.

    You can use the parameters of New-Variable to set the properties of the Variable (such as those that create read-only or constant Variables), set the scope of a Variable, and determine whether Variables are public or private.

    Typically, you create a new Variable by typing the Variable name and its value, such as “$var = 3”, but you can use the New-Variable cmdlet to use its parameters.

PARAMETERS
    -Description <string>
        Specifies a description of the Variable.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Allows you to create a new Variable with the same name as an existing read-only Variable.

        By default, you can overwrite a Variable unless the Variable has an option value of ReadOnly or Constant. For more information, see the Option parameter.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Name <string>
        Specifies a name for the new Variable.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Option <ScopedItemOptions>
        Sets the value of the Options property of the new Variable.

        Valid values are:

        — None: Sets no options. (“None” is the default.)

        — ReadOnly: The value of the Variable cannot be changed except by using the Force parameter. You can use Remove-Variable to delete the Variable.

        — Constant: The Variable cannot be deleted, and its properties cannot be changed. “Constant” is available only when you are creating an Alias. You cannot change the option of an existing Variable to “Constant”.

        — Private: The Variable is available only within the scope specified by the Scope parameter. It is inherited by child scopes. (This value is not related to the “Private” value of the Visibility parameter.)

        — AllScope: The Variable is copied to any new scopes that are created.

        To see the Options property of the Variables, type “Get-Variable| Format-Table -property name, options -autosize”.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns an object representing the new Variable. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Scope <string>
        Determines the scope of the new Variable. Valid values are “Global”, “Local”, or “Script”, or a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). “Local” is the default. For more information, see about_scopes.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Value <Object>
        Specifies the initial value of the Variable.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -Visibility <SessionStateEntryVisibility>
        Determines whether the Variable is visible outside of the session in which it was created. This parameter is designed for use in scripts and commands that will be delivered to other users.

        Valid values are:

        — Public: The Variable is visible. (“Public” is the default.)
        — Private: The Variable is not visible.

        When a Variable is private, it does not appear in lists of Variables, such as those returned by Get-Variable, or in displays of the Variable: drive. Commands to read or change the value of a private Variable return an error. However, the user can run commands that use a private Variable if the commands were written in the session in which the Variable was defined.

        Required?                    false
        Position?                    named
        Default value                Public
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Object
        You can pipe a value to New-Variable.

OUTPUTS
    None or System.Management.Automation.PSVariable
        When you use the PassThru parameter, New-Variable generates a System.Management.Automation.PSVariable object representing the new Variable. Otherwise, this cmdlet does not generate any output.

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>New-Variable days

    Description
    ———–
    This command creates a new Variable named “days”. It has no value immediately following the command.

    ————————– EXAMPLE 2 ————————–

    C:\PS>New-Variable zipcode -Value 98033

    Description
    ———–
    This command creates a Variable named “zipcode” and assigns it the value “98033”.

    ————————– EXAMPLE 3 ————————–

    C:\PS>New-Variable -Name max -Value 256 -Option readonly

    New-Variable -Name max -Value 1024

    New-Variable -Name max -Value 1024 -Force

    C:\PS> New-Variable -Name max -Value 256 -Option readonly

    C:\PS> New-Variable -Name max -Value 1024
    New-Variable : A Variable with name ‘max’ already exists.
    At line:1 char:13
    + New-Variable <<<< -Name max -Value 1024

    C:\PS> New-Variable -Name max -Value 1024 -Force

    Description
    ———–
    This example shows how to use the ReadOnly option of New-Variable to protect a Variable from being overwritten.

    The first command creates a new Variable named Max and sets its value to “256”. It uses the Option parameter with a value of ReadOnly.

    The second command tries to create a second Variable with the same name. This command returns an error, because the read-only option is set on the Variable.

    The third command uses the Force parameter to override the read-only protection on the Variable. In this case, the command to create a new Variable with the same name succeeds.

    ————————– EXAMPLE 4 ————————–

    C:\PS>New-Variable -Name counter -Visibility private

    #Effect of private Variable in a module.

    C:\PS> Get-Variable c*

    Name                         Value
    —-                         —–
    Culture                        en-US
    ConsoleFileName
    ConfirmPreference             High
    CommandLineParameters         {}

    C:\PS> $counter
    “Cannot access the Variable ‘$counter’ because it is a private Variable

    C:\PS> Get-Counter
    Name         Value
    —-         —–
    Counter1     3.1415
    …

    Description
    ———–
    This command demonstrates the behavior of a private Variable in a module. The module contains the Get-Counter cmdlet, which has a private Variable named “Counter”. The command uses the Visibility parameter with a value of “Private” to create the Variable.

    The sample output shows the behavior of a private Variable. The user who has loaded the module cannot view or change the value of the Counter Variable, but the Counter Variable can be read and changed by the commands in the module.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113361
    Get-Variable
    Set-Variable
    Remove-Variable
    Clear-Variable

New-Alias

NAME
    New-Alias

SYNOPSIS
    Creates a new Alias.

SYNTAX
    New-Alias [-Name] <string> [-Value] <string> [-Description <string>] [-Force] [-Option {None | ReadOnly | Constant | Private | AllScope}] [-PassThru] [-Scope <string>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The New-Alias cmdlet creates a new Alias in the current Windows PowerShell session. Aliases created by using New-Alias are not saved after you exit the session or close Windows PowerShell. You can use the Export-Alias cmdlet to save your Alias information to a file. You can later use Import-Alias to retrieve that saved Alias information.

PARAMETERS
    -Description <string>
        Specifies a description of the Alias. You can type any string. If the description includes spaces, enclose it in quotation marks.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        If set, act like Set-Alias if the Alias named already exists.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Name <string>
        Specifies the new Alias. You can use any alphanumeric characters in an Alias, but the first character cannot be a number.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Option <ScopedItemOptions>
        Sets one or more optional properties of the Alias. Valid values are:

        — None: Sets no options. (default)

        — ReadOnly: The Alias cannot be changed unless you use the Force parameter.

        — Constant: The Alias cannot be changed, even by using the Force parameter.

        — Private: The Alias is available only within the scope specified by the Scope parameter. It is invisible in all other scopes.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns an object representing the new Alias. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Scope <string>
        Specifies the scope of the new Alias. Valid values are “Global”, “Local”, or “Script”, or a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). “Local” is the default. For more information, see about_scopes.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Value <string>
        Specifies the name of the cmdlet or command element that is being Aliased.

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to this cmdlet.

OUTPUTS
    None or System.Management.Automation.AliasInfo
        When you use the Passthru parameter, New-Alias generates a System.Management.Automation.AliasInfo object representing the new Alias. Otherwise, this cmdlet does not generate any output.

NOTES

        To create a new Alias, use Set-Alias or New-Alias. To change an Alias, use Set-Alias. To delete an Alias, use Remove-Item.

    ————————– EXAMPLE 1 ————————–

    C:\PS>New-Alias list Get-ChildItem

    Description
    ———–
    This command creates an Alias named “list” to represent the Get-ChildItem cmdlet.

    ————————– EXAMPLE 2 ————————–

    C:\PS>New-Alias -Name w -Value Get-WmiObject -Description “quick wmi Alias-Option ReadOnly

    C:\PS> Get-Alias -Name w | Format-List *

    Description
    ———–
    This command creates an Alias named “w” to represent the Get-WmiObject cmdlet. It creates a description, “quick wmi Alias“, for the Alias and makes it read only. The last line of the command uses Get-Alias to get the new Alias and pipes it to Format-List to display all of the information about it.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113352
    Set-Alias
    Get-Alias
    Export-Alias
    Import-Alias