用命令来操作vSphere:二十二 PowerCLI命令--虚拟主机操作(1)

1.Move-VMHost

功能:移动主机到另一个位置。

语法:

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

例子:

Move-VMHost 10.23.112.113 -Destination Datacenter

2.Restart-VMHost

功能:重新启动指定的主机。

语法:

Restart-VMHost [-VMHost] <VMHost[]> [-Force] [-Evacuate] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Restart-VMHost 10.23.112.235 -RunAsync -Confirm

3.Set-VMHost

功能:更改主机的配置。

语法:

Set-VMHost [-VMHost] <VMHost> [[-State] <VMHostState>] [-VMSwapfilePolicy <VMSwapfilePolicy>] [-VMSwapfileDatastore <Datastore>] [-Profile <VMHostProfile>] [-Evacuate] [-TimeZone <VMHostTimeZone>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Set-VMHost -VMHost Host -State "Disconnected"

(2)

$cluster = Get-Cluster -VMHost Host $task = Set-VMHost -VMHost Host -State "Maintenance" -RunAsync Get-DrsRecommendation -Cluster $cluster | where {$_.Reason -eq "Host is entering maintenance mode"} | Apply-DrsRecommendation $host = Wait-Task $updateHostTask

4.Start-VMHost

功能:启动指定的主机。

语法:

Start-VMHost [-VMHost] <VMHost[]> [-TimeoutSeconds <Int32>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Start-VMHost 10.23.112.235 -RunAsync

5.Stop-VMHost

功能:关指定的主机。

语法:

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

例子:

Stop-VMHost 10.23.112.235 -Confirm

6.Suspend-VMHost

功能:暂停主机。

语法:

Suspend-VMHost [-VMHost] <VMHost[]> [-TimeoutSeconds <Int32>] [-Evacuate] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Suspend-VMHost 10.23.112.54 -TimeOutSeconds 60 -Confirm

7.Get-VMHostAccount

功能:检索vSphere服务器上可用的主机帐户。

语法:

Get-VMHostAccount [-Group] [-User] [[-Id] <String[]>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostAccount -Group

8.New-VMHostAccount

功能:创建一个新的用户或组。

语法:

New-VMHostAccount [-Id] <String> [-Password] <String> [-Description <String>] [-UserAccount] [-AssignGroups <String[]>] [-GrantShellAccess] [-Server <VIServer>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-VMHostAccount [-Id] <String> [-GroupAccount] [-AssignUsers <String[]>] [-Server <VIServer>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

New-VMHostAccount -ID User1 -Password pass –UserAccount

New-VMHostAccount -Id Group1 -GroupAccount -AssignUsers User1

9.Remove-VMHostAccount

功能:删除指定的主机帐户。

语法:

Remove-VMHostAccount [-HostAccount] <HostAccount[]> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Get-VMHostAccount -Group -ID user | Remove-VMHostAccount -Confirm

10.Set-VMHostAccount

功能:配置主机帐户。

语法:

Set-VMHostAccount [-GroupAccount] <Object> [-AssignUsers <String[]>] [-UnassignUsers <String[]>] [-Server <VIServer>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VMHostAccount [-UserAccount] <Object> [-Password <String>] [-Description <String>] [-AssignGroups <String[]>] [-UnassignGroups <String[]>] [-GrantShellAccess [<Boolean>]] [-Server <VIServer>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$userAccount = New-VMHostAccount -ID User1 -Password pass -UserAccount $groupAccount = New-VMHostAccount -ID Group1 -GroupAccount -AssignUsers User1 Set-VMHostAccount -UserAccount $userAccount -UnassignGroups Group1

11.Get-VMHostAdvancedConfiguration

功能:检索主机高级配置。

语法:

Get-VMHostAdvancedConfiguration [[-Name] <String[]>] [-VMHost] <VMHost[]> [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostAdvancedConfiguration -VMHost 10.23.123.100 -Name net*tcp*

12.Set-VMHostAdvancedConfiguration

功能:更新主机的高级配置设置。

语法:

Set-VMHostAdvancedConfiguration [[-Name] <String>] [[-Value] <Object>] [-VMHost] <VMHost[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VMHostAdvancedConfiguration [[-NameValue] <Hashtable>] [-VMHost] <VMHost[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Get-VMHost 10.23.123.344 | Set-VmHostAdvancedConfiguration -Name Migrate.NetTimeout -Value ( [system.int32] 10 )

(2)

$migrationSettings = Get-VMHost 10.23.123.344| Get-VmHostAdvancedConfiguration -Name Migrate.* Set-VmHostAdvancedConfiguration -VMHost 10.23.123.546 -NameValue $migrationSettings

(3)

Set-VMHostAdvancedConfiguration -VMHost 10.23.112.120 -Name Migrate.Enabled -Value 1  

13.Get-VMHostAvailableTimeZone

功能:检索指定主机上使用的时区。

语法:

Get-VMHostAvailableTimeZone [-VMHost] <VMHost[]> [[-Name] <String[]>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostAvailableTimeZone -Name Pacific* -VMHost 10.23.112.19

14.Get-VMHostDiagnosticPartition

功能:检索对指定的主机的诊断分区的列表。

语法:

Get-VMHostDiagnosticPartition [-VMHost] <VMHost[]> [-All] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHost 192.168.1.10 | Get-VMHostDiagnosticPartition –All

 

15.Set-VMHostDiagnosticPartition

功能:激活或停用的主机的诊断分区。

语法:

Set-VMHostDiagnosticPartition [-Active] [<Boolean>] [-VMHostDiagnosticPartition] <VMHostDiagnosticPartition[]> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$diagPartition = Get-VMHostDiagnosticPartition -VMHost $host $diagPartition | Set-VMHostDiagnosticPartition -Active $false -Confirm

16.Get-VMHostFirmware

功能:获取主机的固件信息。

语法:

Get-VMHostFirmware [-VMHost] <VMHost[]> [-Server <VIServer[]>] [<CommonParameters>]
Get-VMHostFirmware [-VMHost] <VMHost[]> [-BackupConfiguration] -DestinationPath <String> [-Server <VIServer[]>] [<CommonParameters>]

例子:

(1)

Get-VMHostFirmware -VMHost $host

 

(2)

Get-VMHostFirmware -VMHost $host -BackupConfiguration -DestinationPath C:\Downloads  

17.Set-VMHostFirmware

功能:设置主机固件。

语法:

Set-VMHostFirmware [-VMHost] <VMHost> [-BackupConfiguration] -DestinationPath <String> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VMHostFirmware [-VMHost] <VMHost> [-ResetToDefaults] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VMHostFirmware [-VMHost] <VMHost> [-Restore] [-SourcePath <String>] [-Force] [-HostCredential <PSCredential>] [-HostUser <String>] [-HostPassword <SecureString>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Set-VMHostFirmware -VMHost Host -DestinationPath 'c:\' –BackupConfiguration

(2)

Set-VMHostFirmware -VMHost Host -Restore -SourcePath c:\bundleToRestore.tgz -HostUser User -HostPassword Pass

(3)

Get-VMHostFirmware -VMHost Host1, Host2 -BackupConfiguration -DestinationPath c:\StoredBundles Set-VMHostFirmware -VMHost Host1, Host2 -Restore -SourcePath c:\StoredBundles -HostUser User -HostPassword Pass

18.Get-VMHostModule

功能:检索指定的主机模块的选项字符串。

语法:

Get-VMHostModule [-Name] <String[]> [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostModule -Name Shaper

19.Set-VMHostModule

功能:覆盖与给定的主机模块的选项。

语法:

Set-VMHostModule [-HostModule] <VmHostModule> [-Options] <String> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

$module = Get-VMHostModule -Name Shaper Set-VMHostModule -HostModule $module -Options "New options text"

(2)

Get-VMHostModule Shaper | Set-VMHostModule -Options "New options text" -Confirm

20.Get-VMHostPatch

功能:检索对指定的主机中安装的主机修补程序的信息。

语法:

Get-VMHostPatch [[-VMHost] <VMHost[]>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostPatch Host

21.Install-VMHostPatch

功能:更新指定的主机。

语法:

Install-VMHostPatch [-VMHost] <VMHost[]> -HostPath <String[]> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]
Install-VMHostPatch [-VMHost] <VMHost[]> -WebPath <String[]> [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]
Install-VMHostPatch [-VMHost] <VMHost[]> -LocalPath <String[]> [-HostUsername <String>] [-HostPassword <SecureString>] [-HostCredential <PSCredential>] [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Install-VMHostPatch -VMHost $host1,$host2 -LocalPath c:\esx40\patches\ESX400-200906001\metadata.zip -HostUsername admin -HostPassword pass

(2)

$host | Install-VMHostPatch -WebPath http://myInternalWebServer/esx40/ESX400-200906001/metadata.zip

(3)

$datastore = Get-Datastore -Name Datastore Copy-DatastoreItem c:\temp\ESX400-200906001\ $datastore.DatastoreBrowserPath -Recurse $host1,$host2 | Install-VMHostPatch -HostPath /vmfs/volumes/datastore/ESX400-200906001/metadata.zip  

你可能感兴趣的:(vmware,VM,host,esxi,operations,esx,PowerCLI)