Vous êtes sur la page 1sur 12

TOPIC Getting started at the command line in Microsoft System Center Virtual Machine Manager (VMM) GETTING STARTED

- VIRTUAL MACHINE MANAGER TUTORIAL -------------------------------------------------You can use standard Windows PowerShell cmdlets in conjunction with the cmdlets provided by Virtual Machine Manager for system administration and to automate administrative tasks. You can manage virtual machine hosts, library servers, virtual machines, and other Virtual Machine Manager components and resources interactively at the command line or by using task-based scripting. This topic shows you how to get started at the command line. For a help topic that provides a "first look" at scripting, type at the command prompt: Get-Help about_VMM_Scripting Both standard Windows PowerShell cmdlets and cmdlets provided by Virtual Machine Manager are available on any computer on which the Virtual Machine Manager Administrator Console is installed. The examples in this topic assume that you have installed the Administrator Console (and thus the Windows PowerShell Virtual Machine Manager command shell) on your Virtual Machine Manager server. This help topic describes: * * * * * * * How How How How How How How to to to to to to to find the Virtual Machine Manager command shell use basic Windows PowerShell cmdlets get information about Virtual Machine Manager cmdlets get information about Virtual Machine Manager use Virtual Machine Manager help topics search or save command-line help topics find more information (the "SEE ALSO" section)

HOW TO FIND THE VIRTUAL MACHINE MANAGER COMMAND SHELL ------------------------------------------------------------To open the command shell from the Windows desktop All Programs menu: 1. On a Virtual Machine Manager server on which the Administrator Console for Virtual Machine Manager is installed, click Start, point to All Programs, point to Microsoft System Center Virtual Machine Manager 2007, and then click Windows PowerShell Virtual Machine Manager. 2. When the command shell opens, confirm that the Virtual Machine Manager snap-in has loaded by typing the following command at the command line: Get-Help Get-VMMServer 3. Confirm that a help topic about the Virtual Machine Manager cmdlet Get-VMMServer is displayed to verify that the Virtual Machine Manager snap-in is loaded. NOTE: You can substitute any Virtual Machine Manager cmdlet for Get-VMMServer. To open the Virtual Machine Manager command shell from the standard Windows PowerShell command shell:

1. On a Virtual Machine Manager server on which the Administrator Console for Virtual Machine Manager is installed, click Start, point to All Programs, point to Windows PowerShell 1.0, and then click Windows PowerShell. The menu from which you just opened Windows PowerShell also includes the following documentation about Windows PowerShell: * * * * Getting Started Quick Reference Release Notes User Guide

NOTE: For a comprehensive introduction to Windows PowerShell, review each of those documents. 2. When the Windows PowerShell command shell opens, to open the Virtual Machine Manager version of the command shell and thus load the Virtual Machine Manager cmdlets, type: Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager 3. When the command shell opens, confirm that the Virtual Machine Manager snap-in has loaded by typing the following command at the command line: Get-Help New-VM -detailed 4. Confirm that a help topic about the Virtual Machine Manager cmdlet New-VM is displayed to verify that the Virtual Machine Manager snap-in is loaded. NOTE: You can substitute any Virtual Machine Manager cmdlet for New-VM. TIP: You can open multiple command shells at the same time. For example, you might want to read help topic examples in one window and try running the examples in another window. HOW TO USE BASIC WINDOWS POWERSHELL CMDLETS ------------------------------------------You can use many standard Windows PowerShell cmdlets in conjunction with the Virtual Machine Manager cmdlets. Two standard Windows PowerShell cmdlets that you need to be familiar with are Get-Help and Get-Command. The example commands in this section will work in either the standard Windows PowerShell command shell or in the Virtual Machine Manager command shell. NOTE: Examples use capital letters for readability, but Windows PowerShell is not case sensitive. To display basic information provided by Get-Help and Get-Command: 1. In one command shell window, type this command and review its output: Get-Help Get-Help NOTE: Typing Get-Help <AnyCmdlet-Name> displays help information about the second cmdlet.

2. In another command shell window, type this command and review its output: Get-Command The Get-Command cmdlet lists all Windows PowerShell cmdlets, including all Virtual Machine Manager cmdlets (if you are in the Virtual Machine Manager command shell, as these examples assume). Later, you will learn how to list only Virtual Machine Manager cmdlets. To clear the screen, type: Clear-Host To display detailed information about Get-Help and Get-Command: 1. In one command shell window, type this command and review its output: Get-Help Get-Help -detailed 2. In another command shell window, type this command and review its output: Get-Help Get-Command -detailed NOTE: When you include the -detailed parameter, the help includes a description for each parameter (but excludes other parameter details). To display full information about Get-Help and Get-Command: 1. In one command shell window, type this command and review its output: Get-Help Get-Help -full 2. In another command shell windows, type this command and review its output: Get-Help Get-Command -full NOTE: When you include the -full parameter, the help includes all available information about each parameter. To display only the examples for Get-Help and Get-Command: 1. In one command shell window, type this command and review its output: Get-Help Get-Help -example 2. In another command shell window, type this command and review its output: Get-Help Get-Command -example NOTE: When you include the -example parameter, the help displays only the Synopsis and the set of examples for that cmdlet.

To display a help topic one screen at a time: 1. Type the following command to see the help topic for Get-Command (or any cmdlet) one screen at a time: Help Get-Command -full 2. Press the spacebar to display the next screen. NOTE: If you press ENTER, only one additional line at a time displays. HOW TO GET INFORMATION ABOUT VIRTUAL MACHINE MANAGER CMDLETS -----------------------------------------------------------For the commands in the preceding section to work, you can use either the standard Windows PowerShell command shell or the Virtual Machine Manager command shell. However, for the commands in this and subsequent sections to work, you must be in the Virtual Machine Manager command shell (see "How to Find the Virtual Machine Manager Command Shell" earlier in this topic). To list all Windows PowerShell snap-ins: 1. Type the following command and review its output: Get-PSSnapin 2. Confirm that you see the list of standard Windows PowerShell snap-ins (such as Microsoft.PowerShell.Core) followed by the Virtual Machine Manager snap-in. NOTE: If Microsoft.SystemCenter.VirtualMachineManager does not appear in the list of snap-ins, you are probably working in the Windows PowerShell command shell rather than in the Virtual Machine Manager extension of the command shell (see "How to Find the Virtual Machine Manager Command Shell" earlier in this topic). To list only cmdlets included in the Virtual Machine Manager snap-in: 1. Type the following command and review its output: Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager 2. Confirm that you see a list of cmdlets that includes cmdlets that are clearly Virtual Machine Manager cmdlets, such as Add-VMHost, Get-VM, or Update-VMMManagedComputer. To list only Virtual Machine Manager cmdlets in a different format, type the following command and review its output: Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager Sort-Object Noun Format-Table -Group Noun NOTE: If you want to learn more about the standard Windows PowerShell cmdlets Sort-Object or Format-Table, type the following two commands:

Get-Help Sort-Object Get-Help Format-Table To discover where the command shell finds different types of cmdlets: 1. In one command shell window, type this command and review its output: Get-Command Get-VMMServer implementingtype,pssnapin Format-List -property

NOTE: If you want to learn more about the standard Windows PowerShell cmdlet Format-List, type Get-Help Format-List. 2. In another command shell window, type this command and review its output: Get-Command Get-Help Format-List -property implementingtype,pssnapin

3. Compare the output of both commands and confirm that you can discover by looking at the output the origin of each cmdlet (Get-VMMServer and Get-Help). To display information about the command that connects to the Virtual Machine Manager database: 1. Type the following command and review its output: Get-Help Get-VMMServer detailed 2. Review the DETAILED DESCRIPTION and the examples. Most multiple-line interactive commands used to administer Virtual Machine Manager start by using this cmdlet to connect to Virtual Machine Manager. To display only the syntax for Get-VMMServer, type the following command and review its output: Get-Command Get-VMMServer -Syntax NOTE: This method of displaying only the syntax is an alternative to typing Get-Help Get-VMMServer (which displays other information in addition to the syntax). To view help for a cmdlet that has more than one parameter set: 1. Type the following command and review its output: Get-Help Add-VMHost 2. Confirm that the output has the following two sets of parameters available for use with the Add-VMHost cmdlet, depending on whether you will add the host to your primary network or to a perimeter network: Add-VMHost -Credential <Credential> [-EncryptionKey <String>] [-Reassociate] [-RunAsynchronously <Boolean>] [-VMMServer] [-VMRCEnabled] [-VMRCTimeoutEnabled] [-VMRCTimeoutMinutes] [<CommonParameters>]

Add-VMHost -PerimeterNetworkHost -SecurityFile <String> [-EncryptionKey <String>] [-Reassociate] [-RunAsynchronously <Boolean>] [-VMMServer] [-VMRCEnabled] [-VMRCTimeoutEnabled] [-VMRCTimeoutMinutes] [<CommonParameters>] To display the description of a specific parameter: 1. Look at the first parameter set for Add-VMHost (in the preceding example), and then type this command and review its output: Get-Help Add-VMHost -parameter Reassociate 2. Look at the second parameter set for Add-VMHost (in the preceding example), and then type this command and review its output: Get-Help Add-VMHost -parameter PerimeterNetworkHost 3. Look at either parameter set for Add-VMHost (in the preceding example), and then type this command and review its output: Get-Help about_CommonParameters NOTE: You must use a different command to display information about the parameter called <CommonParameters> because this set of parameters is shared by most cmdlets (both standard Windows PowerShell cmdlets and Virtual Machine Manager cmdlets). For more information, type: Get-Help about_CommonParameters. To see how Get-Help and Get-Command handle wildcards: 1. In one command shell window, type this command and review its output: Get-Help *virtualcom* 2. In another command shell windows, type this command and review its output: Get-Command *virtualcom* 3. Confirm that the output for step 1 shows the first part of the Synopsis for each cmdlet that contains the string "virtualcom" in its name, whereas the output for step 2 shows the first part of the syntax for each cmdlet that contains the string "virtualcom" in its name. To view a limited set of properties for cmdlets by using wildcards: 1. In one command shell window, type this command and review its output: Get-Help *virtualcom* Format-List -property Name, Synopsis

2. In another command shell windows, type this command and review its output: Get-Command *virtualcom* Format-List -property Name, ImplementingType

HOW TO GET INFORMATION ABOUT VIRTUAL MACHINE MANAGER ---------------------------------------------------Although you can display help about Virtual Machine Manager cmdlets at any time (as shown in the preceding section), you cannot actually use any of the Virtual Machine Manager cmdlets until after you connect to the Virtual Machine Manager server. Connecting to the Virtual Machine Manager server retrieves the server object from the Virtual Machine Manager database and gives you access to all other objects in the database for as long as the connection lasts or until you close the command shell window. IMPORTANT: The examples in this section assume that you have access to a Virtual Machine Manager server on which the Administrator Console is installed and that at least one virtual machine host, library server, and virtual machine exist. To connect to the Virtual Machine Manager server, type the following command (substituting your own server and domain names) review the output: Get-VMMServer Computername <YourVMMServerName>.<YourDomainName>.com When the command completes successfully: * SERVER OBJECT IS RETURNED. The shell displays information about the properties of the Virtual Machine Manager server object. * DATABASE IS AVAILABLE. You are now connected to the Virtual Machine Manager database provided by the Virtual Machine Manager server. IMPORTANT: In the rest of this tutorial, many of the commands require that you be connected to the Virtual Machine Manager database. If you find that a command does not work, try running the command in this procedure again. If you encounter problems, try one of the following: * Open the Services tool in Administrative Tools and restart the Virtual Machine Manager service. * Type Get-Help Restart-Service -detailed to read the standard Windows PowerShell help topic that tells you how to restart a service at the command line. To connect to Virtual Machine Manager if it is installed on the local host, type the following command and review its output: Get-VMMServer Computername localhost NOTE: If you are working on the server on which Virtual Machine Manager is installed (rather than accessing it remotely), you can substitute "localhost" for the fully qualified domain name (FQDN). To display information only about specific properties of the VMMServer object, type the following command and review its output:

Get-VMMServer -Computername <YourVMMServerName>.<YourDomainName>.com Format-List -property Name, FullyQualifiedDomainName, PlacementGoal, MemoryPriority, DiskIOPriority, CPUPriority, NetworkPriority To display information about specific properties of servers that host virtual machines and library servers, grouped by name: 1. Type the following command and review its output: Get-VMMManagedComputer -GroupBy Role Format-List -property Name,Role,State

2. Type the following command and review its output: Get-VMMManagedComputer -GroupBy Role Format-Table -property Name,Role,State,

To display all properties and methods available for the Virtual Machine Manager server object: 1. Type the following command to connect to the Virtual Machine Manager server and store the server object in variable $VMMServer: $VMMServer = Get-VMMServer Computername "<YourVMMServerName>.<YourDomainName>.com" 2. Type the following command to display the contents of $VMMServer to confirm that this variable contains the server object: $VMMServer 3. Type the following command to pass the contents of $VMMServer to Get-Member, which displays the properties and methods associated with the server object: $VMMServer Get-Member

NOTE: The properties of the object are its characteristics. The methods of the object are the actions that you can perform on the entity (such as a server or virtual machine) that this object represents. To list cmdlets associated with commonly used Virtual Machine Manager verbs, type one or more of the following series of commands: TIP: After you type the first command, use the UP arrow to repeat the command, and then (instead of hitting ENTER), backspace to delete New, and then type Add. Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager -Verb New Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager -Verb Add Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager -Verb Get

Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager -Verb Set Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager -Verb Remove To list cmdlets associated with commonly used Virtual Machine Manager nouns, type one or more of the following series of commands: TIP: In this example (in contrast to the preceding example), you can omit typing PSSnapin Microsoft.SystemCenter.VirtualMachineManager because all of the nouns are unique to Virtual Machine Manager. Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Get-Command Noun Noun Noun Noun Noun Noun Noun Noun Noun Noun Noun Noun Noun Noun VMMServer VMHost MachineConfig LibraryServer LibraryShare VM HardwareProfile GuestOSProfile Template VirtualNetwork VMHostNetworkAdapter VirtualNetworkAdapter SelfServiceWebServer SelfServicePolicy

HOW TO USE VIRTUAL MACHINE MANAGER HELP TOPICS ---------------------------------------------One way to start using Virtual Machine Manager cmdlets is by experimenting with the Get cmdlets. These cmdlets retrieve Virtual Machine Manager objects from the Virtual Machine Manager database managed by the Virtual Machine Manager service. You can display information about an object or store an object in a variable to be used by a subsequent cmdlet. To list only the Virtual Machine Manager cmdlets that begin with Get, type the following command (shown earlier) and review its output: Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager Verb Get To display examples for the following Virtual Machine Manager Get cmdlets, type one or more of the following series of commands: Get-Help Get-Help Get-Help Get-Help Get-Help Get-Help Get-Help Get-Help Get-VMMServer example Get-VMHost example Get-LibraryServer example Get-VMMManagedComputer -example Get-VM example Get-Template example Get-HardwareProfile -example Get-GuestOSProfile example

NOTE: As you display the examples for a specific cmdlet in one command shell window, try executing one or more of the examples in another command shell window.

To review how to view an entire help topic, type one or both of the following commands and review the output: Get-Help <Cmdlet-Name> -detailed Get-Help <Cmdlet-Name> -full HOW TO SEARCH OR SAVE COMMAND-LINE HELP TOPICS ---------------------------------------------This section shows you how to search cmdlet help topics from the command line and how to save one or all help topics to a text file. To search the main Windows PowerShell cmdlet help files: 1. Type the following command to change to the directory where the standard Windows PowerShell help files are stored: cd $pshome 2. Confirm that the new path in the command prompt changes to: PS <C>:\WINDOWS\system32\WindowsPowerShell\v1.0> where "<C>" is the drive on which Windows is installed on this computer. 3. Type the following command to search the standard Windows PowerShell help topics for the string "credential parameter" (or specify a different string): findstr /I /C:credential parameter" *.xml, *.txt To search the Virtual Machine Manager cmdlet help files: 1. Type the following command to change to the directory where the Virtual Machine Manager help files are stored: cd <C>:\'Program Files'\'Microsoft System Center Virtual Machine Manager 2007'\bin Replace "<C>" with the letter of the drive on which your Virtual Machine Manager files are installed, and confirm that the command prompt changes to the Virtual Machine Manager bin directory. 2. Type the following command to search the Virtual Machine Manager help topics for the string "library server" (or specify a different string): findstr /I /C:credential parameter *.xml, *.txt To display information about the findstr command, type the following command and review its output: findstr /? NOTE: The findstr command is a Cmd.exe command. Windows PowerShell supports many legacy Cmd.exe and UNIX commands.

To return to your home directory, type the following command: cd $home To save a single help topic to a text file: 1. Type the following command to change to your My Documents folder: cd 'My Documents' 2. Type the following command to save the contents of a single help topic (in this example, Get-VMHostRating) to a text file: Get-Help Get-VMHostRating -detailed Out-File Get-VMHostRating.txt

3. Open Windows Explorer and then open Get-VMHostRating.txt in your My Documents folder to confirm that the text file contains the help topic for Get-VMHostRating. To save all help topics for every Virtual Machine Manager cmdlet to a text file: 1. Type the following command and review its output: Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager Get-Help -detailed Out-File <C>:\<FolderName>\VMMHelpTopics.txt Replace "<C>" with the letter of the drive on which you want to store VMMHelpTopics.txt, and replace "<FolderName>" with the name of the folder on that drive in which you want to store VMMHelpTopics.txt. IMPORTANT: 2. Open Windows Explorer and then open VMMHelpTopics.txt in the folder in which you stored the file to confirm that the text file contains the help topics for all Virtual Machine Manager cmdlets. SEE ALSO -------For more information about standard Windows PowerShell conceptual topics, type "Get-Help about_<TopicName>" for the following topics: * * * * * * * * * * * * * * about_Alias about_Array about_Assignment_Operators about_Command_Syntax about_Comparison_Operators about_Core_commands about_Filter about_Object about_Parameter about_Pipeline about_Property about_Provider about_PSSnapins about_Where

For more information about Virtual Machine Manager conceptual topics, type "Get-Help about_<TopicName>" for the following topics: * about_VMM * about_VMM_Scripting

Vous aimerez peut-être aussi