Appendix B: Introductory Command-Line Tutorial
You can use the standard Microsoft Windows PowerShell cmdlets with the cmdlets that are provided by Virtual Machine Manager for interactive system administration and for scripting administrative tasks. Standard Windows PowerShell cmdlets and Virtual Machine Manager cmdlets are available on any computer on which the Virtual Machine Manager Administrator Console is installed.
The examples in this tutorial assume that you have installed the Administrator Console and the Windows PowerShell – Virtual Machine Manager command shell on your Virtual Machine Manager server.
How to Find the Virtual Machine Manager Command Shell
You can open the Windows PowerShell - Virtual Machine Manager command shell by using either of the methods shown in the following two procedures.
To open the Virtual Machine Manager command shell from the All Programs menu
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.
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
If a Help topic about the Virtual Machine Manager cmdlet Get-VMMServer is displayed, the Virtual Machine Manager snap-in is loaded. You can substitute any Virtual Machine Manager cmdlet for Get-VMMServer.
To open the Virtual Machine Manager command shell from the Windows PowerShell command shell
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
For a comprehensive introduction to Windows PowerShell, review each of the documents.
When the Windows PowerShell command shell opens, open the Windows PowerShell – Virtual Machine Manager version of the command shell and load the Virtual Machine Manager cmdlets, by typing:
Add-PSSnapin VirtualMachineManagerSnapin
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
If a Help topic about the Virtual Machine Manager cmdlet New-VM is displayed, the Virtual Machine Manager snap-in is loaded. You can substitute any Virtual Machine Manager cmdlet for New-VM.
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 standard Windows PowerShell cmdlets with Virtual Machine Manager cmdlets. To get started, two standard Windows PowerShell cmdlets that you need to be familiar with are Get-Help and Get-Command.
Note
Examples use uppercase letters for readability, but Windows PowerShell is not case sensitive.
To display basic information provided by Get-Help and Get-Command
In the Windows PowerShell – Virtual Machine Manager command-shell window, type the following command and review its output:
Get-Help Get-Help
Typing
Get-Help <AnyCmdlet-Name>
displays Help information about the second cmdlet.In another Windows PowerShell – Virtual Machine Manager command-shell window, type the following 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 Windows PowerShell – 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 the following command to clear the screen:
Clear-Host
Alternatively, you can use one of the aliases for this cmdlet,
Clear
orCls
.
To display detailed information about Get-Help and Get-Command
In one command-shell window, type the following command and review its output:
Get-Help Get-Help -detailed
In another command-shell window, type the following command and review its output:
Get-Help Get-Command -detailed
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
In one command-shell window, type the following command and review its output:
Get-Help Get-Help -full
In another command-shell window, type the following command and review its output:
Get-Help Get-Command -full
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
In one command-shell window, type the following command and review its output:
Get-Help Get-Help -example
In another command-shell window, type the following command and review its output:
Get-Help Get-Command -example
When you include the
-example
parameter, the Help displays only theSynopsis
and the set of examples for that cmdlet.
To display a Help topic one screen at a time
Type the following command to see the Help topic for Get-Command or for any cmdlet, one screen at a time:
Help Get-Command -full
Press the Spacebar to display the next screen.
If you press ENTER, only one additional line at a time is displayed.
How to Get Information About Virtual Machine Manager Cmdlets
This section shows you how to get basic information about Virtual Machine Manager cmdlets.
To list all Windows PowerShell snap-ins
Type the following command and review its output:
Get-PSSnapin
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.If
VirtualMachineManagerSnapin
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 document).
To list only cmdlets included in the Virtual Machine Manager snap-in
Type the following command and review its output:
Get-Command -PSSnapin VirtualMachineManagerSnapin
Confirm that you see a list of cmdlets that includes 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 VirtualMachineManagerSnapin | Sort-Object Noun | Format-Table -Group Noun
If you want to learn more about the standard Windows PowerShell cmdlets Sort-Object or Format-Table, type
Get-Help Sort-Object
and typeGet-Help Format-Table
.
To discover where the shell finds different types of cmdlets
In one command-shell window, type the following command and review its output:
Get-Command Get-VMMServer | Format-List -property implementingtype,pssnapin
If you want to learn more about the standard Windows PowerShell cmdlet Format-List, type
Get-Help Format-List
.In another command-shell window, type the following command and review its output:
Get-Command Get-Help | Format-List -property implementingtype,pssnapin
Compare the output of both commands and confirm that you can discover the origin of each cmdlet by looking at the output:
For Get-VMMServer, confirm that the output is:
ImplementingType : Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.ConnectServerCmdlet PSSnapIn : VirtualMachineManagerSnapIn
For Get-Help, confirm that the output is:
ImplementingType : Microsoft.PowerShell.Commands.GetHelpCommand PSSnapIn : Microsoft.PowerShell.Core
To display information about the command that connects to the Virtual Machine Manager database
Type the following command and review its output:
Get-Help Get-VMMServer –detailed
Review the
DETAILED DESCRIPTION
and the examples. Most multiple-line interactive commands that are used to administer Virtual Machine Manager start by using the Get-VMMServer cmdlet to connect to Virtual Machine Manager:Get-VMMServer -ComputerName YourVMMServerName.YourDomainName.com
To display only the syntax for Get-VMMServer
Type the following command and review its output:
Get-Command Get-VMMServer -Syntax
This method of displaying only the syntax is an alternative to using 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
Type the following command and review its output:
Get-Help Add-VMHost
Confirm that the output has the following two sets of parameters available for use with the Add-VMHost cmdlet, depending on whether you are adding 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
Look at the first parameter set for Add-VMHost (in the preceding example procedure), type the following command, and then review its output:
Get-Help Add-VMHost -parameter Reassociate
Look at the second parameter set for Add-VMHost (in the preceding example procedure), type the following command, and then review its output:
Get-Help Add-VMHost -parameter PerimeterNetworkHost
Look at either parameter set for Add-VMHost (in the preceding example procedure), type the following command, and then review its output:
Get-Help about_CommonParameters
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).
To see how Get-Help and Get-Command handle wildcards
In one command-shell window, type the following command and review its output:
Get-Help *virtualcom*
In another command-shell window, type the following command and review its output:
Get-Command *virtualcom*
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, and 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
In one command-shell window, type the following command and review its output:
Get-Help *virtualcom* | Format-List -property Name, Synopsis
In another command-shell window, type the following command and review its output:
Get-Command *virtualcom* | Format-List -property Name, ImplementingType
How to Get Information About Virtual Machine Manager
When you open a Windows PowerShell – Virtual Machine Manager command-shell window, you can display Help about Virtual Machine Manager cmdlets at any time (as shown in the preceding section), but 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 SQL Server database, which stores all Virtual Machine Manager objects 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, and review the output:
Get-VMMServer –Computername “<YourVMMServerName>.<YourDomainName>.com”
When the command is completed successfully:
- Server object is returned. The shell displays information about the properties of the Virtual Machine Manager server object.
- Database is available. You are connected to the Virtual Machine Manager database that is provided by the Virtual Machine Manager server.
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, trying opening the Services tool in Administrative Tools and restart the Virtual Machine Manager service (or 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
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 host servers and library servers, grouped by name
Type the following command and review its output:
Get-VMMManagedComputer | Format-List -property Name,Role,State -GroupBy Role
Type the following command and review its output:
Get-VMMManagedComputer | Format-Table -property Name,Role,State, -GroupBy Role
To display all properties and methods available for the Virtual Machine Manager server object
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"
Type the following command to display the contents of $VMMServer to confirm that this variable contains the server object:
$VMMServer
Type the following command to pass the contents of $VMMServer to the standard Windows PowerShell cmdlet Get-Member, which displays the properties and methods that are associated with this server object:
$VMMServer | Get-Member
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:
Get-Command -PSSnapin VirtualMachineManagerSnapin -Verb New Get-Command -PSSnapin VirtualMachineManagerSnapin -Verb Add Get-Command -PSSnapin VirtualMachineManagerSnapin -Verb Get Get-Command -PSSnapin VirtualMachineManagerSnapin -Verb Set Get-Command -PSSnapin VirtualMachineManagerSnapin -Verb Remove
After you type the first command, use the UP arrow to repeat the command, and (instead of pressing ENTER), backspace to delete
New
, and then typeAdd
.
To list cmdlets associated with commonly used Virtual Machine Manager nouns
Type one or more of the following series of commands:
Get-Command –Noun VMMServer Get-Command –Noun VMHost Get-Command –Noun MachineConfig Get-Command –Noun LibraryServer Get-Command –Noun LibraryShare Get-Command –Noun VM Get-Command –Noun HardwareProfile Get-Command –Noun GuestOSProfile Get-Command –Noun Template Get-Command –Noun VirtualNetwork Get-Command –Noun VMHostNetworkAdapter Get-Command –Noun VirtualNetworkAdapter Get-Command –Noun SelfServiceWebServer Get-Command –Noun SelfServicePolicy
In this example (in contrast to the preceding example), you can omit typing
PSSnapin VirtualMachineManagerSnapin
because all the nouns are unique to Virtual Machine Manager.
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 that is managed by the Virtual Machine Manager service. You can display information about an object, or you can 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 and review its output:
Get-Command -PSSnapin VirtualMachineManagerSnapin –Verb Get
To display examples for the following key Virtual Machine Manager “Get” cmdlets
Type one or more of the following series of commands:
Get-Help Get-VMMServer –example Get-Help Get-VMHost –example Get-Help Get-LibraryServer –example Get-Help Get-VMMManagedComputer -example Get-Help Get-VM –example Get-Help Get-Template –example Get-Help Get-HardwareProfile -example Get-Help Get-GuestOSProfile –example
As you display the examples for a specific cmdlet in one command-shell window, try running one or more of the examples in another command-shell window. After you are comfortable using the “Get” cmdlets, you might want to display the examples for the “New,” “Add,” “Set,” “Remove,” and other cmdlets and use or adapt those examples as you experiment with your own Virtual Machine Manager environment.
How to Search or Save Cmdlet 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
Type the following command to change to the directory where the standard Windows PowerShell Help files are stored:
Set-Location $pshome
Note
Alternatively, you can use the alias for Set-Location:
cd $pshome
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 the Windows operating system is installed on this computer.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
Note
For information about when single and double quotes are interchangeable in Windows PowerShell—and when they are not—type at the command prompt:
Get-Help about_quoting_rules
To search the Virtual Machine Manager cmdlet Help files
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 Managerbin
directory.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:”library server” *.xml, *.txt
To display information about the findstr command
Type the following command and review its output:
findstr /?
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 to return to your home directory:
cd $home
Note
By default, your home directory is:
<C>:\Documents and Settings\YourAlias>
To save a single Help topic to a text file
Type the following command to change to your My Documents folder:
cd 'My Documents'
Type the following commands to save the contents of a single Help topic (in this example, the Help topics for Get-VMHostRating and Remove-VirtualNetworkAdapter) to a text file:
Get-Help Get-VMHostRating -detailed | Out-File Get-VMHostRating.txt
Alternatively, you can use the redirection operator:
Get-Help Remove-VirtualNetworkAdapter -detailed > Get-VMHostRating.txt
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
Type the following command and review its output:
Get-Command -PSSnapin VirtualMachineManagerSnapin | Get-Help -detailed | Out-File <C>:\<FolderName>\VMMHelpTopics.txt
Replace "
<C>
" with the letter of the drive on which you want to store VMMHelpTopics, and replace "<FolderName>
" with the name of the folder on that drive in which you want to store VMMHelpTopics.If you see an error message indicating that a Help topic for one or more cmdlets could not be found, the command should still run correctly and should put a copy of all existing cmdlet Help topics into the VMMHelpTopics.txt file.
To confirm that the text file contains the Help topics for all Virtual Machine Manager cmdlets, open Windows Explorer and then open VMMHelpTopics.txt in the folder in which you stored the file.
Useful Windows PowerShell Command-Line Help Topics
To list the standard Windows PowerShell conceptual topics, type:
Get-Command about_*
To view any of these topics, type:
Get-Help about_<TopicName>