1.Import-VMHostProfile
功能:从一个文件中导入主机配置文件。文件路径必须从vSphere PowerCLI客户端访问。
语法:
Import-VMHostProfile [-FilePath] <String> [-Name] <String> [[-ReferenceHost] <VMHost>] [-Description <String>] [-Server <VIServer>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Import-VMHostProfile -FilePath export.prf -Name Profile
2.New-VMHostProfile
功能:创建一个基于主机参考的新主机配置文件。
语法:
New-VMHostProfile [-Name] <String> [-ReferenceHost] <VMHost> [-Description <String>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$h = Get-VMHost 10.23.134.133 New-VMHostProfile -Name testProfile -Description "This is my first test profile." -ReferenceHost $h
3.Remove-VMHostProfile
功能:删除指定的主机配置文件。
语法:
Remove-VMHostProfile [-Profile] <VMHostProfile[]> [[-Server] <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Remove-VMHostProfile -Entity <InventoryItem[]> [[-Server] <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Get-VMHostProfile -Name Profile | Remove-VMHostProfile -Confirm:$false
4.Set-VMHostProfile
功能:修改指定的主机配置文件。
语法:
Set-VMHostProfile [[-Name] <String>] [[-ReferenceHost] <VMHost>] [-Profile] <VMHostProfile> [-Description <String>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$profile = ( Get-VMHostProfile -Name Profile )[0] Set-VMHostProfile -Profile $profile -Description "New description."
5.Test-VMHostProfileCompliance
功能:测试配置文件符合主机。
语法:
Test-VMHostProfileCompliance [-VMHost] <VMHost[]> [-UseCache] [[-Server] <VIServer[]>] [<CommonParameters>]
Test-VMHostProfileCompliance [-Profile] <VMHostProfile[]> [-UseCache] [[-Server] <VIServer[]>] [<CommonParameters>]
例子:
(1)
Test-VMHostProfileCompliance -VMHost Host
(2)
$profile = Get-VMHostProfile -Name Profile Apply-VMHostProfile -AssociateOnly -Profile $profile -Entity 10.0.0.126 Test-VMHostProfileCompliance -VMHost 10.0.0.126 | fl *
(3)
Test-VMHostProfileCompliance -Profile $profile | fl *
6.Get-VMHostRoute
功能:检索指定的主机路由表的路由。
语法:
Get-VMHostRoute [[-VMHost] <VMHost[]>] [-Server <VIServer[]>] [<CommonParameters>]
例子:
(1)
Get-VMHostRoute -VMHost $host
(2)
Get-VMHostRoute -VMHost $host1, $host2 -Server $server1, $server2
7.New-VMHostRoute
功能:在指定主机上创建一个新的路由表。
语法:
New-VMHostRoute [-VMHost] <VMHost[]> -Destination <IPAddress> -Gateway <IPAddress> -PrefixLength <Int32> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
New-VMHostRoute -VMHost 10.23.114.195 -Destination 192.168.103.102 -PrefixLength 32 -Gateway 10.23.84.53
8.Remove-VMHostRoute
功能:删除主机路由。
语法:
Remove-VMHostRoute [-VMHostRoute] <VMHostRoute[]> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$destIpList = ('192.168.111.101', '192.168.111.102') $routes = Get-VMHostRoute -VMHost ($script:vmhost1, $script:vmhost2) | where {$destIpList -contains $_.Destination.IPAddressToString} Remove-VMHostRoute -VMHostRoute $routes -Confirm:$false
9.Set-VMHostRoute
功能:修改路由表中的主机路由。
语法:
Set-VMHostRoute [-VMHostRoute] <VMHostRoute[]> [-Destination <IPAddress>] [-Gateway <IPAddress>] [-PrefixLength <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)
$hostroute = New-VMHostRoute -VMHost 10.23.114.189 -Destination 192.168.104.101 -Gateway 10.23.84.69 -PrefixLength 32 $hostroute | Set-VMHostRoute -Gateway 10.23.84.70
(2)
$hostroute1 = New-VMHostRoute -VMHost 10.23.114.189 -Destination 192.168.104.101 -Gateway 10.23.84.69 -PrefixLength 32 $hostroute2 = New-VMHostRoute -VMHost 10.23.114.190 -Destination 192.168.104.101 -Gateway 10.23.84.70 -PrefixLength 32 Set-VMHostRoute -VMHostRoute ($hostroute1, $hostroute2) -Destination 192.168.104.0 -PrefixLength 24
10.Get-VMHostService
功能:获取主机的服务信息。
语法:
Get-VMHostService [-VMHost] <VMHost[]> [-Server <VIServer[]>] [-Refresh] [<CommonParameters>]
例子:
Get-VMHostService -Refresh
11.Restart-VMHostService
功能:重新启动指定的主机服务。
语法:
Restart-VMHostService [-HostService] <HostService[]> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$sshd = Get-VMHostService -VMHost $host | where {$_.Key -eq 'sshd'} Restart-VMHostService $sshd -Confirm
12.Set-VMHostService
功能:修改主机服务。
语法:
Set-VMHostService [-HostService] <HostService> [-Policy] <HostServicePolicy> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$service = Get-VmHostService -VMHost Host Set-VMHostService -Service $service -Policy "Automatic"
13.Start-VMHostService
功能:启动指定的主机服务。
语法:
Start-VMHostService [-HostService] <HostService[]> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$vmHostService = Get-VmHostService -VMHost Host if ($vmHostService[0].Running -eq "False") { Start-VmHostService -Service $vmHostService[0] } else { Stop-VmHostService -Service $vmHostService[0]
14.Stop-VMHostService
功能:停止主机服务。
语法:
Stop-VMHostService [-HostService] <HostService[]> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$vmHostService = Get-VmHostService -VMHost Host if ($vmHostService[0].Running -eq "False") { Start-VmHostService -Service $vmHostService[0] } else { Stop-VmHostService -Service $vmHostService[0]
15.Get-VMHostStartPolicy
功能:检索主机启动策略
语法:
Get-VMHostStartPolicy [-VMHost] <VMHost[]> [-Server <VIServer[]>] [<CommonParameters>]
例子:
Get-VMHostStartPolicy -VMHost 10.23.113.212
16.Set-VMHostStartPolicy
功能:更新主机的默认启动策略
语法:
Set-VMHostStartPolicy [-VMHostStartPolicy] <VMHostStartPolicy> [-Enabled [<Boolean>]] [-StartDelay <Int32>] [-StopAction <VmStopAction>] [-StopDelay <Int32>] [-WaitForHeartBeat [<Boolean>]] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
$hoststartpolicy = Get-VMHostStartPolicy -VMHost Host Set-VMHostStartPolicy -VMHostStartPolicy $hoststartpolicy -StopAction PowerOff
17.Get-VMHostSysLogServer
功能:显示指定主机的远程syslog服务。
语法:
Get-VMHostSysLogServer [-VMHost] <VMHost[]> [-Server <VIServer[]>] [<CommonParameters>]
例子:
$sysLogServer = Get-VMHostSysLogServer -VMHost 10.23.123.234
18.Set-VMHostSysLogServer
功能:配置指定的主机的远程syslog服务。
语法:
Set-VMHostSysLogServer [[-SysLogServer] <NamedIPEndPoint>] [-VMHost] <VMHost[]> [-SysLogServerPort <Int32>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)
Set-VMHostSysLogServer -SysLogServer '192.168.0.1:133' -VMHost Host
(2)
Set-VMHostSysLogServer -SysLogServer $null -VMHost Host