Command Precedence

適用於: Virtual Machine Manager 2008 R2, Virtual Machine Manager 2008 R2 SP1

When you import more than one module or snap-in into a Windows PowerShell session, the session might contain more than one command that uses the same name. For example, if you type Get-Help Get-Job in the Windows PowerShell – Virtual Machine Manager command shell on a computer on which Windows PowerShell 2.0 is installed, Get-Help returns two help objects: one for the System Center Virtual Machine Manager (VMM) Get-Job cmdlet, and one for the Windows PowerShell Get-Job cmdlet. The Get-Help output resembles the following:

Name      Category    Synopsis
----      --------    --------
Get-Job   Cmdlet      Gets Virtual Machine Manager job objects on the Virtual Machine Manager server.
Get-Job   Cmdlet      Gets Windows PowerShell background jobs that are running in the current session.

The Stop-Job cmdlet will also return a similar result.

How Command Precedence is Determined

When a Windows PowerShell session includes more than one command that has the same name, Windows PowerShell determines which command to run by using the following rules.

If a session contains items of the same type

When the session contains items of the same type that have the same name, Windows PowerShell runs the item that was added to the session most recently. For example, when you type Get-Job in the VMM command shell, the VMM Get-Job cmdlet runs because the VMM snap-in was added to the session most recently.

If you specify the qualified name of the cmdlet

If you specify the name of the command qualified by the snap-in or module in which it originated, for example, Microsoft.SystemCenter.VirtualMachineManager\Get-Job, Windows PowerShell runs the specified command. This format ensures that you run the command that you intend. For example, if you type Get-Help Microsoft.SystemCenter.VirtualMachineManager\Get-Job at the VMM command shell prompt, you will get the help topic for the VMM Get-Job cmdlet. For an example of how to use a qualified cmdlet name in a script, see GetLibraryAuditRecords.ps1.

If you do not specify the qualified name of the cmdlet

If you do not specify the qualified name of the cmdlet that you want to run, Windows PowerShell uses the following precedence order to determine which command to run:

  1. Alias

  2. Function

  3. Cmdlet

  4. Native Windows commands

Therefore, if you type "Get-Job", Windows PowerShell looks first for an alias named "Get-Job", then a function named "Get-Job", and finally a cmdlet named "Get-Job". It runs the first "Get-Job" item that it finds.

For more information about command precedence, at the command prompt, type Get-Help about_Command Precedence.