1.get-vm
功能:检索ESX服务器上的vSphere的虚拟机。
语法:
Get-VM [-Datastore <Datastore[]>] [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]
Get-VM [-DistributedSwitch <DistributedSwitch[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]
例子:
2.move-vm
功能:把虚拟机移动到另一个位置。
语法:
Move-VM [[-Destination] <VIContainer>] [-Datastore <Datastore>] [-DiskStorageFormat <VirtualDiskStorageFormat>] [-RunAsync] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)Get-VM -Name winxp | Move-VM -Destination 10.23.112.235 将虚拟机winxp从目前的位置移动到IP地址为10.23.112.235的虚拟机主机上。(2)Move-VM -VM winxp -Destination ResourcePool 移动虚拟机winxp到ResourcePool。 ESX主机不会改变。3.new-vm
功能:创建一个新的虚拟机。
语法:
New-VM [-VMHost] <VMHost> [-Version <VMVersion>] -Name <String> [-ResourcePool <ResourcePool>] [-VApp <VApp>] [-Location <Folder>] [-Datastore <Datastore>] [-DiskMB <Int64[]>] [-DiskPath <String[]>] [-DiskStorageFormat <VirtualDiskStorageFormat>] [-MemoryMB <Int64>] [-NumCpu <Int32>] [-Floppy] [-CD] [-GuestId <String>] [-AlternateGuestName <String>] [-NetworkName <String[]>] [-HARestartPriority <HARestartPriority>] [-HAIsolationResponse <HAIsolationResponse>] [-DrsAutomationLevel <DrsAutomationLevel>] [-VMSwapfilePolicy <VMSwapfilePolicy>] [-Server <VIServer[]>] [-RunAsync] [-Description <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-VM [-VMHost] <VMHost> [-Name <String>] [-ResourcePool <ResourcePool>] [-VApp <VApp>] [-Location <Folder>] [-Datastore <Datastore>] [-DiskStorageFormat <VirtualDiskStorageFormat>] [-OSCustomizationSpec <OSCustomizationSpec>] [-HARestartPriority <HARestartPriority>] [-HAIsolationResponse <HAIsolationResponse>] [-DrsAutomationLevel <DrsAutomationLevel>] [-Server <VIServer[]>] [-RunAsync] [-Description <String>] -VM <VirtualMachine[]> [-WhatIf] [-Confirm] [<CommonParameters>]
New-VM [-VMHost] <VMHost> -Name <String> [-ResourcePool <ResourcePool>] [-VApp <VApp>] [-Location <Folder>] [-Datastore <Datastore>] [-Template] <Template> [-DiskStorageFormat <VirtualDiskStorageFormat>] [-OSCustomizationSpec <OSCustomizationSpec>] [-HARestartPriority <HARestartPriority>] [-HAIsolationResponse <HAIsolationResponse>] [-DrsAutomationLevel <DrsAutomationLevel>] [-Server <VIServer[]>] [-RunAsync] [-Description <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-VM [-VMHost] <VMHost> [-Name <String>] [-ResourcePool <ResourcePool>] [-VApp <VApp>] [-Location <Folder>] [-HARestartPriority <HARestartPriority>] [-HAIsolationResponse <HAIsolationResponse>] [-DrsAutomationLevel <DrsAutomationLevel>] -VMFilePath <String> [-Server <VIServer[]>] [-RunAsync] [-Description <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)New-VM -Name VM -VMHost Host -ResourcePool ResourcePool -DiskMB 4000 -MemoryMB 256
(2)New-Template -VM VM1 -Name Template -Location Datacenter
New-VM -Name VM2 -Template Template -VMHost $host
创建模板从VM1虚拟机的虚拟机模板。然后创建一个虚拟机基于模板的命名将VM2
(3)New-VM -VM VM1, VM2 -Location Folder -VMHost Host
(4)$vm2 = New-VM -Name VM2 -VM VM1 -Datastore $datastore -VMHost $host
(5)$vm = Get-VM VM*
New-VM -VM $vm -VMHost $host
(6)cd vmstores:\myserver@443\Datacenter\Storage1\myvm\
$vmxFile = Get-Item *.vmx
New-VM -VMHost $host -VMFilePath $vmxFile.DatastoreFullPath
4.remove-vm
功能:从vSphere删除服务器上指定的虚拟机。
语法:
Remove-VM [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Remove-VM -DeletePermanently [-RunAsync] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Remove-VM winxp -DeletePermanently
5.set-vm
功能:更改虚拟机的配置。
语法:
Set-VM [-VM] <VirtualMachine> [-Name <String>] [-Version <VMVersion>] [-MemoryMB <Int64>] [-NumCpu <Int32>] [-GuestId <String>] [-AlternateGuestName <String>] [-OSCustomizationSpec <OSCustomizationSpec>] [-HARestartPriority <HARestartPriority>] [-HAIsolationResponse <HAIsolationResponse>] [-DrsAutomationLevel <DrsAutomationLevel>] [-Server <VIServer[]>] [-RunAsync] [-VMSwapFilePolicy <VMSwapfilePolicy>] [-Description <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VM [-VM] <VirtualMachine> [-Name <String>] [-Snapshot <Snapshot>] [-OSCustomizationSpec <OSCustomizationSpec>] [-HARestartPriority <HARestartPriority>] [-HAIsolationResponse <HAIsolationResponse>] [-DrsAutomationLevel <DrsAutomationLevel>] [-Server <VIServer[]>] [-RunAsync] [-VMSwapFilePolicy <VMSwapfilePolicy>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VM [-VM] <VirtualMachine> [-Name <String>] [-Server <VIServer[]>] [-RunAsync] [-ToTemplate] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)Set-VM -VM VM -Name VM1 -GuestId "winXPProGuest" -Description "My updated virtual machine."(2)$template = Get-VM VM | Set-VM -ToTemplate -Name VMTemplate
6.start-vm
功能:启动ESX上的虚拟机
语法:
Start-VM [-RunAsync] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Start-VM -VM winxp -Confirm -RunAsync
7.stop-vm
功能:关闭ESX上的虚拟机
语法:
Stop-VM [-Kill] [-RunAsync] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)Stop-VM -VM VM �CConfirm
(2)Stop-VM -VM VM -Kill -Confirm:$false
8.restart-vm
功能:重启虚拟机
语法:
Restart-VM [-RunAsync] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Restart-VM -VM winxp -RunAsync -Confirm
9.suspend-vm
功能:暂停虚拟机。
语法:
Suspend-VM [-RunAsync] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Get-VM VM | Suspend-VM
10.get-cddrive
功能:检索虚拟CD驱动器。
语法:
Get-CDDrive [[-VM] <VirtualMachine[]>] [[-Template] <Template[]>] [[-Snapshot] <Snapshot[]>] [-Server <VIServer[]>] [<CommonParameters>]
例子:
Get-VM -Name VM | Get-CDDrive11.new-cddrive
功能:创建一个新的虚拟光盘驱动器。
语法:
New-CDDrive [-IsoPath <String>] [-HostDevice <String>] [-StartConnected] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
New-CDDrive -VM $vm -ISOPath "Path_to_ISO\test.iso"12.remove-cddrive
功能:移除虚拟CD驱动器。
语法:
Remove-CDDrive [-CD] <CDDrive[]> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$cd = Get-CDDrive -VM $vm -Template $template Remove-CDDrive -CD $cd13.set-cddrive
功能:设置虚拟机光盘驱动器的配置。
语法:
Set-CDDrive [-CD] <CDDrive[]> [-IsoPath <String>] [-HostDevice <String>] [-NoMedia] [-StartConnected [<Boolean>]] [-Connected [<Boolean>]] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$cd = New-CDDrive -VM VM -ISOPath "[sof-20666-esx:storage1] ISO\testISO.iso" Set-CDDrive -CD $cd -NoMedia14.get-floppydrive
功能:检索上的vSphere的虚拟服务器上可用的软盘驱动器。
语法:
Get-FloppyDrive [[-VM] <VirtualMachine[]>] [[-Template] <Template[]>] [[-Snapshot] <Snapshot[]>] [-Server <VIServer[]>] [<CommonParameters>]
例子:
Get-FloppyDrive -VM VM15.new-floppydrive
功能:创建一个新的虚拟软盘驱动器。
语法:
New-FloppyDrive [-FloppyImagePath <String>] [-NewFloppyImagePath <String>] [-HostDevice <String>] [-StartConnected] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
New-FloppyDrive -VM VM -HostDevice '/dev/fd0' -StartConnected16.remove-floppydrive
功能:删除虚拟软盘驱动器。
语法:
Remove-FloppyDrive [-Floppy] <FloppyDrive[]> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$floppy = Get-FloppyDrive -VM VM Remove-FloppyDrive -Floppy $floppy17.set-floppydrive
功能:配置虚拟软盘驱动器。
语法:
Set-FloppyDrive [-Floppy] <FloppyDrive[]> [-FloppyImagePath <String>] [-HostDevice <String>] [-NoMedia] [-StartConnected [<Boolean>]] [-Connected [<Boolean>]] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Set-FloppyDrive -Floppy $floppy -StartConnected:$true18.copy-harddisk
功能:复制一个虚拟硬盘到另一个目的地。
语法:
Copy-HardDisk [-HardDisk] <HardDisk[]> [-DestinationPath] <String> [-DestinationStorageFormat <VirtualDiskStorageFormat>] [-Force] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)Get-HardDisk -VM $vm | Copy-HardDisk "[Storage1]/"
(2)Copy-HardDisk -HardDisk $hdd -DestinationPath "[Storage1] vms/disks" -DestinationStorageFormat Thick
19.get-harddisk功能:检索上的vSphere的虚拟服务器上可用的硬盘。
语法:
Get-HardDisk [-Path <DatastoreItem[]>] [-DiskType <DiskType[]>] [-Server <VIServer[]>] [<CommonParameters>]
Get-HardDisk -Datastore <Datastore[]> [-DatastorePath <String[]>] [-DiskType <DiskType[]>] [-Server <VIServer[]>] [<CommonParameters>]
Get-HardDisk [-DiskType <DiskType[]>] [[-VM] <VirtualMachine[]>] [[-Template] <Template[]>] [[-Snapshot] <Snapshot[]>] [-Server <VIServer[]>] [<CommonParameters>]
例子:
(1)Get-HardDisk -VM VM
(2)Get-HardDisk -VM $vm -DiskType flat
(3)Get-HardDisk -Datastore "Storage1" -DatastorePath "[Storage1] myVM/"
20.new-harddisk
功能:在指定的位置添加一个新的硬盘。
语法:
New-HardDisk [[-Persistence] <String>] [-Controller <ScsiController>] [[-DiskType] <DiskType>] [-CapacityKB <Int64>] [-Split] [-ThinProvisioned] [-StorageFormat <VirtualDiskStorageFormat>] [-DeviceName <String>] [-Datastore <Datastore>] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-HardDisk [[-Persistence] <String>] [-Controller <ScsiController>] -DiskPath <String> [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)$vm = Get-VM VM
$vm | New-HardDisk -CapacityKB 10000 -Persistence persistent
21.remove-harddisk
功能:删除指定的虚拟硬盘。
语法:
Remove-HardDisk [-HardDisk] <HardDisk[]> [-DeletePermanently] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Get-HardDisk -VM $vm | Remove-HardDisk