您的位置:首页 > 其它

用命令来操作vSphere:十九 PowerCLI命令--vShphere服务器(1) 推荐

2011-06-21 22:39 471 查看
1.Get-Annotation

功能:检索注释

语法:

Get-Annotation [[-CustomAttribute] <CustomAttribute[]>] [-Entity] <InventoryItem> [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-Cluster Cluster | Get-Annotation -CustomAttribute PhysicalLocation

2.Set-Annotation

功能:更改指定注释的名称

语法:

Set-Annotation [-Entity] <InventoryItem> [-CustomAttribute] <CustomAttribute> [-Value] <String> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Set-Annotation -Entity $host -CustomAttribute "PhysicalLocation" -Value SofiaOffice

(2)

Get-Cluster Cluster | Set-Annotation -CustomAttribute "PhysicalLocation" -Value California

3.Get-CustomAttribute

功能:检索自定义属性。

语法:

Get-CustomAttribute [[-Name] <String[]>] [[-TargetType] <CustomAttributeTargetType[]>] [-Global] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-CustomAttribute -Name Cluster* -TargetType Cluster

4.New-CustomAttribute

功能:创建一个新的自定义属性。

语法:

New-CustomAttribute [-Name] <String> [[-TargetType] <CustomAttributeTargetType[]>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

New-CustomAttribute -Name "CompanyName" -TargetType VMHost, VirtualMachine

5.Remove-CustomAttribute

功能:删除自定义属性。

语法:

Remove-CustomAttribute [-CustomAttribute] <CustomAttribute[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Remove-CustomAttribute -CustomAttribute "CompanyID", "Owner" -Server $agent007

6.Set-CustomAttribute

功能:重命名自定义属性。

语法:

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

例子:

Set-CustomAttribute -CustomAttribute "PhysicalLocation" -Name "Area"

7.Remove-CustomField

功能:删除一个特定清单项目类型的新的自定义字段。

语法:

Remove-CustomField [-Entity] <InventoryItem> [-Name] <String> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Remove-CustomField -Entity VM -Name CPUMaxLoad

8.New-CustomField

功能:创建一个特定清单项目类型的新的自定义字段。

语法:

New-CustomField [-Entity] <InventoryItem> [-Name] <String> [[-Value] <String>] [-Global] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

New-CustomField -Entity VM -Name CPUMaxLoad -Value 300

9.Set-CustomField

功能:设置为特定的清单项目的自定义字段的值。

语法:

Set-CustomField [-Entity] <InventoryItem> [-Name] <String> [[-Value] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Get-VM VM | Set-CustomField -Name CF - Value 10

10.Get-Datacenter

功能:检索存储上提供一个vSphere服务器。

语法:

Get-Datacenter [-VM <VirtualMachine[]>] [-Cluster <Cluster[]>] [-VMHost <VMHost[]>] [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-Datacenter -Name Datacenter*

11.New-Datastore

功能:创建一个新的数据存储。

语法:

New-Datastore [-Server <VIServer[]>] [-VMHost] <VMHost[]> [-Name] <String> -Path <String> [-Nfs] -NfsHost <String> [-ReadOnly] [-WhatIf] [-Confirm] [<CommonParameters>]

New-Datastore [-Server <VIServer[]>] [-VMHost] <VMHost[]> [-Name] <String> -Path <String> [-Vmfs] [-BlockSizeMB <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>]

New-Datastore [-Server <VIServer[]>] [-VMHost] <VMHost[]> [-Name] <String> -Path <String> -NfsHost <String> [-ReadOnly] [-Cifs] -Username <String> -Password <String> [-WhatIf] [-Confirm] [<CommonParameters>]

New-Datastore [-Server <VIServer[]>] [-VMHost] <VMHost[]> [-Name] <String> -Path <String> [-Local] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

New-Datastore -Nfs -VMHost 10.23.112.345 -Name Datastore -Path $remotePath -NfsHost $remoteHost

(2)

Get-VMHost | New-Datastore -Nfs -Name NFS1 -Path "/mnt/nfs1/nfs11/test1" -NfsHost 10.91.246.21

12.Remove-Datastore

功能:移除指定位置的数据存储。

语法:

Remove-Datastore [-Datastore] <Datastore> [-VMHost] <VMHost> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Remove-Datastore -Datastore Datastore -VMHost 10.23.112.234 -Confirm:$false

13.Set-Datastore

功能:更改指定数据存储的属性。

语法:

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

例子:

Get-Datastore -Name Datastore1 | Set-Datastore -Name Datastore2

14.Get-Datastore

功能:检索vSphere服务器上的数据存储。

语法:

Get-Datastore [-Server <VIServer[]>] [[-Name] <String[]>] [-Datacenter <Datacenter[]>] [-VMHost <VMHost[]>] [-VM <VirtualMachine[]>] [-Entity <VIObject[]>] [-Refresh] [<CommonParameters>]

例子:

(1)

Get-Datastore -VMHost (Get-VMHost -Id HostSystem-host-8)

(2)

$datastores = Get-Datastore | where {$_.type -eq "NFS"}

15.Copy-DatastoreItem

功能:在数据存储和数据存储之间复制本地文件系统。

语法:

Copy-DatastoreItem [-Item] <Object[]> [[-Destination] <Object>] [-Force] [-PassThru] [-Recurse] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Copy-DatastoreItem ds:\VM\* c:\VMFolder\VM\

(2)

Copy-DatastoreItem c:\VMFolder\NewVM\* ds:\VM\ -Force

16.Apply-DrsRecommendation

功能:应用指定的DRS设置。

语法:

Apply-DrsRecommendation [-DrsRecommendation] <DrsRecommendation[]> [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Get-DrsRecommendation -Priority 1,2 | Apply-DrsRecommendation

(2)

$drs = Get-DrsRecommendation -Cluster Cluster Apply-DrsRecommendation -DrsRecommendation $drs -RunAsync

17.Get-DrsRecommendation

功能:检索DRS群集可用的设置。

语法:

Get-DrsRecommendation [[-Cluster] <Cluster[]>] [-Refresh] [-Priority <Int32[]>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

(1)

Get-Cluster Cluster | Get-DrsRecommendation -Priority 4,5

(2)

Get-DrsRecommendation -Cluster Cluster –Refresh

18.Get-DrsRule

功能:检索DRS规则指定的集群名单。

语法:

Get-DrsRule [[-Name] <String[]>] [-Cluster] <Cluster[]> [[-VM] <VirtualMachine[]>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-DrsRule -Cluster $cluster -Name "*Rule1*"

19.New-DrsRule

功能:创建一个新的DRS规则。

语法:

New-DrsRule [-Name] <String> [-Cluster] <Cluster[]> [-Enabled [<Boolean>]] -KeepTogether [<Boolean>] -VM <VirtualMachine[]> [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

New-DrsRule -Cluster $cluster -Name antiAffinityRule1 -KeepTogether $false -VM $antiAffinityVMs

201.Remove-DrsRule

功能:删除一个DRS规则。

语法:

Remove-DrsRule [-Rule] <DrsVMAffinityRule[]> [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$rules = Get-DrsRule -Cluster $cluster -Name "*Rule1*" Remove-DrsRule $rules -Confirm:$false

21.Set-DrsRule

功能:修改现有的DRS规则。

语法:

Set-DrsRule [[-Enabled] [<Boolean>]] [-Rule] <DrsVMAffinityRule[]> [-Name <String>] [-VM <VirtualMachine[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$vm = Get-VM DrsRuleVM1* Set-DrsRule -Rule $affinityRule -VM $vm -Enabled $true;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息