用命令来操作vSphere:二十 PowerCLI命令--vShphere服务器(2)

1.Move-Folder

功能:移动一个vSphere文件夹从一个位置到另一个位置。

语法:

Move-Folder [-Folder] <Folder[]> [-Destination] <VIContainer> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$root = Get-Folder –NoRecursion

$folder1 = New-Folder -Name Folder1 -Location $root

$folder2 = New-Folder -Name Folder2 -Location $root

Move-Folder -Folder $folder2 -Destination $folder1

 

2.New-Folder

功能:在vSphere服务器上创建一个新的文件夹。

语法:

New-Folder [-Name] <String> [-Location] <VIContainer> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

New-Folder -Name Folder1 -Location Folder2

 

3.Remove-Folder

功能:删除指定的文件夹。

语法:

Remove-Folder [-Folder] <Folder[]> [-DeletePermanently] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Remove-Folder Folder

 

4.Set-Folder

功能:更改指定文件夹的属性。

语法:

Set-Folder -Folder <Folder> [-Name] <String> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Set-Folder -Folder Folder1 -Name Folder2 -Confirm

 

5.Get-Folder

功能:检索vSphere服务器上可用的文件夹。

语法:

Get-Folder [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]

例子:

(1)

$server = Connect-VIServer -Server 10.23.112.235 Get-Folder -Server $server -Name Folder 

(2)

Get-Folder -NoRecursion

 

6.Get-Inventory

功能:检索在vSphere的服务器上的清单项目。

语法:

Get-Inventory [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-Inventory -Location Datacenter -Name *Pool 

7.Move-Inventory

功能:移动一个vSphere清单项目从一个位置到另一个位置。

语法:

Move-Inventory [-Item] <InventoryItem[]> [-Destination] <VIContainer> [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

$vm = Get-VM -Name VM* Move-Inventory -Item $vm -Destination Folder

 

(2)

Get-Folder Folder1 | Get-Inventory -NoRecursion | Move-Inventory -Destination Folder2 

8.Remove-Inventory

功能:移除指定的地点清单项目。

语法:

Remove-Inventory [-Item] <InventoryItem[]> [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Get-Folder Folder| Get-Inventory -NoRecursion | Remove-Inventory 

9.Get-NetworkAdapter

功能:检索vSphere服务器上的可用虚拟网络适配器。

语法:

Get-NetworkAdapter [[-VM] <VirtualMachine[]>] [[-Template] <Template[]>] [[-Snapshot] <Snapshot[]>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-NetworkAdapter -VM VM

10.Get-Task

功能:检索vSphere服务器上的任务。

语法:

Get-Task [[-Status] <TaskState>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

$serv = Connect-VIServer -Server 10.23.112.235 $task = Get-Task -Server $serv -Status Error $task 

11.Stop-Task

功能:停止指定的任务。

语法:

Stop-Task [-Task] <Task[]> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$task = Remove-VM -VM VM -Confirm -RunAsync Stop-Task -Task $task

 

12.Wait-Task

功能:等待指定任务的完成。

语法:

Wait-Task [-Task] <Task[]> [<CommonParameters>]

例子:

$task = Remove-VM -VM VM -Confirm -RunAsync Wait-Task -Task $task 

13.Get-Template

功能:检索vSphere服务器上可用的虚拟机模板。

语法:

Get-Template [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-Template -Name Web* -Location Datacenter 

14.Remove-Template

功能:从清单中删除指定的虚拟机模板。

语法:

Remove-Template [-Template] <Template[]> [-DeletePermanently] [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Remove-Template -Template $template 

15.New-Template

功能:创建一个新的虚拟机模板。

语法:

New-Template [-VM] <VirtualMachine> [-Name] <String> [-Location] <VIContainer> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

New-Template -VM VM -Name Template -Location Datacenter 

16.Set-Template

功能:更改虚拟机模板的名称和说明。

语法:

Set-Template [-Template] <Template> [-Name <String>] [-ToVM] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Set-Template -Template $template -Name Template2 

(2)

$vm = Set-Template -Template $template -ToVM

 

17.Export-VApp

功能:导出虚拟设备到指定的位置。

语法:

Export-VApp [[-Destination] <String>] [-VApp] <VApp[]> [-Name <String>] [-Force] [-CreateSeparateFolder] [-Description <String>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Get-VApp VApp* | Export-VApp "c:\vapps\" 

(2)

Export-VApp "c:\NewFolder\" $vApp -Name "EMail_vApp" –Force 

(3)

Export-VApp -vApp $vApp -Destination "c:\vapps\Vapp\" -Force -CreateSeparateFolder:$false 

18.Get-VApp

功能:检索虚拟设备

语法:

Get-VApp [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-ResourcePool ResourcePool | Get-VApp –NoRecursion 

19.Import-VApp

功能:导入一个OVF(开放虚拟化格式)封装。该软件包可以包含一个虚拟设备或虚拟机。

语法:

Import-VApp [-Source] <String> [[-Name] <String>] [-Location <VIContainer>] [-VMHost] <VMHost> [-Datastore <Datastore>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Import-VApp -Source D:\vapps\WebApp\WebApp.ovf -VMHost Host -Datastore (Get-Datastore -VMHost Host -Name Datastore) 

20.New-VApp

功能:创建一个新的虚拟设备。

语法:

New-VApp -Location <VIContainer> [-Name] <String> [-CpuExpandableReservation [<Boolean>]] [-CpuLimitMhz <Int64>] [-CpuReservationMhz <Int64>] [-CpuSharesLevel <SharesLevel>] [-MemExpandableReservation [<Boolean>]] [-MemLimitMB <Int64>] [-MemReservationMB <Int64>] [-MemSharesLevel <SharesLevel>] [-NumCpuShares <Int32>] [-NumMemShares <Int32>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]
New-VApp -Location <VIContainer> [[-Name] <String>] -VApp <VApp> [-VMHost <VMHost>] [-Datastore <Datastore>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

New-VApp -Name VApp -CpuLimitMhz 4000 -CpuReservationMhz 1000 –Location Host 

21.Remove-VApp

功能:从服务器中删除虚拟设备。

语法:

Remove-VApp [-DeletePermanently] [-VApp] <VApp[]> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Get-VMHost Host | Get-VApp | Remove-VApp 

22.Set-VApp

功能:配置虚拟设备。

语法:

Set-VApp -VApp <VApp[]> [-Name <String>] [-CpuExpandableReservation [<Boolean>]] [-CpuLimitMhz <Int64>] [-CpuReservationMhz <Int64>] [-CpuSharesLevel <SharesLevel>] [-MemExpandableReservation [<Boolean>]] [-MemLimitMB <Int64>] [-MemReservationMB <Int64>] [-MemSharesLevel <SharesLevel>] [-NumCpuShares <Int32>] [-NumMemShares <Int32>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Get-VApp -Name TestVApp | Set-VApp -CpuSharesLevel Low -MemSharesLevel Normal

 

(2)

$vapp = Get-VApp -Location Datacenter Set-VApp -VApp $vapp -CpuExpandableReservation:$true -CpuLimitMhz 4000 -MemExpandableReservation:$true -MemLimitMB 2048 

23.Start-VApp

功能:启动虚拟设备。

语法:

Start-VApp [-VApp] <VApp[]> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Get-VMHost Host | Get-VApp | Start-VApp 

24.Stop-VApp

功能:停止虚拟设备。

语法:

Stop-VApp [-Force] [-VApp] <VApp[]> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Get-VMHost Host | Get-VApp | Stop-VApp 

25.Get-View

功能:返回vSphere的.NET视图对象对应到指定的搜索条件。

语法:

Get-View [-VIObject] <VIObject[]> [-Property <String[]>] [<CommonParameters>]
Get-View [-Server <VIServer[]>] [-Id] <ManagedObjectReference[]> [-Property <String[]>] [<CommonParameters>]
Get-View [-Server <VIServer[]>] [-SearchRoot <ManagedObjectReference>] -ViewType <Type> [-Filter <Hashtable>] [-Property <String[]>] [<CommonParameters>]

例子:

$vm = Get-View -ViewType VirtualMachine -Filter @{"Name" = "VM"} $hostView = Get-View -ID $vm.Runtime.Host $hostView.Summary.Runtime

26.Get-VIObjectByVIView

功能:转换一个vSphere    .NET中对象的PowerShell VIObject。

语法:

Get-VIObjectByVIView [-VIView] <ViewBase[]> [<CommonParameters>]
Get-VIObjectByVIView [-Server <VIServer[]>] [-MORef] <ManagedObjectReference[]> [<CommonParameters>]

例子:

$view = Get-VM VM | Stop-VM | Get-View $vm = Get-VIObjectByVIView $view | Start-VM

你可能感兴趣的:(vmware,vsphere,esxi,esx,PowerCLI)