用命令来操作vSphere:十三 PowerCLI命令--网络操作(2)

1.Get-VMGuestNetworkInterface

功能:检索有关指定的虚拟机的网络配置。

语法:

Get-VMGuestNetworkInterface [[-VM] <VirtualMachine[]>] [-VMGuest <VMGuest[]>] [-Server <VIServer[]>] [-ToolsWaitSecs <Int32>] [-GuestPassword <SecureString>] [-GuestUser <String>] [-GuestCredential <PSCredential>] [-HostPassword <SecureString>] [-HostUser <String>] [-HostCredential <PSCredential>] [<CommonParameters>]

例子:

Get-VMGuestNetworkInterface -VM $vm -HostUser Admin -HostPassword pass1 -GuestUser User -GuestPassword pass2 

2.Set-VMGuestNetworkInterface

功能:使用VMware的虚拟机工具配置网络设置。

语法:

Set-VMGuestNetworkInterface -VmGuestNetworkInterface <VMGuestNetworkInterface[]> [-WinsPolicy <DhcpPolicy>] [-Wins <String[]>] [-DnsPolicy <DhcpPolicy>] [-Dns <String[]>] [-IPPolicy <DhcpPolicy>] [[-Gateway] <Object>] [[-Netmask] <String>] [[-Ip] <IPAddress>] [-ToolsWaitSecs <Int32>] [-GuestPassword <SecureString>] [-GuestUser <String>] [-GuestCredential <PSCredential>] [-HostPassword <SecureString>] [-HostUser <String>] [-HostCredential <PSCredential>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Set-VMGuestNetworkInterface -VMGuestNetworkInterface $vmGuestNetworkInterface -HostUser Admin -HostPassword Pass01 -GuestUser User -GuestPassword Pass02 -Netmask 255.255.255.255 -Gateway 10.23.112.58 

3.Get-VMGuestRoute

功能:检索指定的虚拟机的路由配置。

语法:

Get-VMGuestRoute [[-VM] <VirtualMachine[]>] [-VMGuest <VMGuest[]>] [-Server <VIServer[]>] [-ToolsWaitSecs <Int32>] [-GuestPassword <SecureString>] [-GuestUser <String>] [-GuestCredential <PSCredential>] [-HostPassword <SecureString>] [-HostUser <String>] [-HostCredential <PSCredential>] [<CommonParameters>]

例子:Get-VMGuestRoute -VM $vm -HostUser Admin -HostPassword pass1 -GuestUser User -GuestPassword pass2

 4.New-VMGuestRoute

功能:添加一个新路径所提供的虚拟机和客户机路由表。

语法:

New-VMGuestRoute [-VM <VirtualMachine[]>] [-Destination] <IPAddress> [[-Netmask] <String>] [-Gateway] <IPAddress> [-Interface <Object>] [-VMGuest <VMGuest[]>] [-Server <VIServer[]>] [-ToolsWaitSecs <Int32>] [-GuestPassword <SecureString>] [-GuestUser <String>] [-GuestCredential <PSCredential>] [-HostPassword <SecureString>] [-HostUser <String>] [-HostCredential <PSCredential>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

New-VMGuestRoute -HostUser admin -HostPassword pass1 -GuestUser user -GuestPassword pass2 -VM $vm -Destination '192.168.100.10' -Netmask '255.255.255.255' -Gateway '10.23.112.58' 

5.Get-VMHostFirewallDefaultPolicy

功能:检索指定的主机防火墙默认策略

语法:

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

例子:

Get-VMHostFirewallDefaultPolicy -VMHost 10.23.123.100

6.Set-VMHostFirewallDefaultPolicy

功能:设置为指定的主机防火墙的默认策略。

语法:

Set-VMHostFirewallDefaultPolicy [[-AllowIncoming] [<Boolean>]] [[-AllowOutgoing] [<Boolean>]] [-Policy] <VMHostFirewallDefaultPolicy[]> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$firewallpolicy = Get-VMHostFirewallDefaultPolicy -VMHost 10.23.123.100 Set-VMHostFirewallDefaultPolicy -Policy $firewallpolicy -AllowOutGoing $true | fl 

7.Get-VMHostFirewallException

功能:检索从指定的主机上的防火墙策略的例外。

语法:

Get-VMHostFirewallException [[-Name] <String[]>] [-VMHost] <VMHost[]> [-Port <Int32[]>] [-Enabled [<Boolean>]] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostFirewallException -VMHost 10.23.123.100 -Enabled $true | fl 

8.Set-VMHostFirewallException

功能:启用或禁用主机防火墙的例外。

语法:

Set-VMHostFirewallException [-Enabled] [<Boolean>] [-Exception] <VMHostFirewallException[]> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$ftpFirewallExceptions = Get-VMHostFirewallException -VMHost $host | where {$_.Name.StartsWith('FTP')} $ftpFirewallExceptions | Set-VMHostFirewallException -Enabled $true 

9.Get-VMHostHba

功能:获取(主机总线适配器)提供的HBA信息。

语法:

Get-VMHostHba [[-VMHost] <VMHost[]>] [[-Device] <String[]>] [-Type <HbaType[]>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostHba -Device *hba0* | fl 

10.Set-VMHostHba

功能:配置给定的iSCSI HBA的CHAP的属性。

语法:

Set-VMHostHba -IScsiHba <IScsiHba[]> [-IScsiName <String>] [-ChapType <ChapType>] [-ChapName <String>] [-ChapPassword <String>] [-MutualChapEnabled [<Boolean>]] [-MutualChapName <String>] [-MutualChapPassword <String>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Get-VMHostHba -Type iScsi | Set-VMHostHba -ChapType Required -ChapName Admin -ChapPassword pass

(2)

Set-VMHostHba -IScsiHba $iscsi -MutualChapEnabled $true -ChapType Required -ChapName Admin -ChapPassword pass -MutualChapName Administrator -MutualChapPassword Pass 

11.Get-VMHostNetwork

功能:检索服务器上的vSphere主机的网络。

语法:

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

例子:

Get-VMHostNetwork -VMHost 10.23.113.212 | fl 

12.Set-VMHostNetwork

功能:更新指定的虚拟网络。

语法:

Set-VMHostNetwork [-Network] <VMHostNetworkInfo> [-ConsoleGateway <String>] [-VMKernelGateway <String>] [-VMKernelGatewayDevice <String>] [-ConsoleGatewayDevice <String>] [-DomainName <String>] [-HostName <String>] [-DnsFromDhcp [<Boolean>]] [-DnsDhcpDevice <Object>] [-DnsAddress <String[]>] [-SearchDomain <String[]>] [-IPv6Enabled [<Boolean>]] [-ConsoleV6Gateway <String>] [-ConsoleV6GatewayDevice <String>] [-VMKernelV6Gateway <String>] [-VMKernelV6GatewayDevice <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

$vmHostNetworkInfo = Get-VmHostNetwork -Host Host Set-VmHostNetwork -Network $vmHostNetworkInfo -VMKernelGateway 10.23.11.11 -DomainName eng.vmware.com -HostName Host1 -DnsFromDhcp $false

(2)

Get-VMHost Host | Get-VMHostNetwork | Set-VMHostNetwork -IPv6Enabled $true Get-VMHost Host | Restart-VMHost -Force -Confirm:$false

(3)

Get-VMHost Host | Get-VMHostNetwork | Set-VMHostNetwork -ConsoleV6Gateway $ipv6GatewayAddress -ConsoleV6GatewayDevice "vswif0"

(4)

Get-VMHost Host | Get-VMHostNetwork | Set-VMHostNetwork -VMKernelV6Gateway $ipv6GatewayAddress 

13.Get-VMHostNetworkAdapter

功能:检索vSphere的服务器主机上的网络适配器

语法:

Get-VMHostNetworkAdapter [[-VMHost] <VMHost[]>] [-Physical] [-VMKernel] [-Console] [[-Name] <String[]>] [-Server <VIServer[]>] [<CommonParameters>]
Get-VMHostNetworkAdapter [[-DistributedSwitch] <DistributedSwitch[]>] [-Physical] [-VMKernel] [-Console] [[-Name] <String[]>] [-Server <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostNetworkAdapter -VMKernel | fl 

14.New-VMHostNetworkAdapter

功能:在指定的主机上创建一个新的HostVirtualNIC(服务控制台或VMkernel)。

语法:

New-VMHostNetworkAdapter [-VMHost] <VMHost> [[-PortGroup] <String>] [-PortKey <String>] [-VirtualSwitch] <VirtualSwitchBase> [[-IP] <String>] [[-SubnetMask] <String>] [[-Mac] <String>] [-Mtu <Int32>] [-ConsoleNic] [-VMotionEnabled [<Boolean>]] [-FaultToleranceLoggingEnabled [<Boolean>]] [-IPv6ThroughDhcp] [-AutomaticIPv6] [-IPv6 <String[]>] [-ManagementTrafficEnabled [<Boolean>]] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

$vs = Get-VirtualSwitch -VMHost 10.23.113.111 -Name vSwitch New-VMHostNetworkAdapter -VMHost 10.23.113.110 -PortGroup MyConsolePortGroup -VirtualSwitch $vs -ConsoleNIC -Mtu 4000

(2)

$vs = Get-VirtualSwitch -VMHost (Get-VMHost 10.23.113.111) -Name "vSwitch0" New-VMHostNetworkAdapter -VMHost (Get-VMHost 10.23.113.110) -PortGroup MyVMKernelPortGroup -VirtualSwitch $vs -IP 192.168.168.110 -SubnetMask 255.255.255.0

(3)

New-VMHostNetworkAdapter -VMHost $vmHost -VirtualSwitch $virtualSwitch -PortGroup "Service Console 1" -IP 192.168.0.1 -SubnetMask 255.255.255.0 -IPv6 "0200:2342::1/32"

(4)

New-VMHostNetworkAdapter -VMHost $myHost -VirtualSwitch $virtualSwitch -PortGroup "Serveice Console 1" -IP 192.168.0.1 -SubnetMask 255.255.255.0 –AutomaticIPv6

(5)

New-VMHostNetworkAdapter -VMHost $vmHost -VirtualSwitch $virtualSwitch -PortGroup "Service Console 1" - -IPv6ThroughDhcp 

15.Remove-VMHostNetworkAdapter

功能:删除指定的主机的网络适配器。

语法:

Remove-VMHostNetworkAdapter [-Nic] <HostVirtualNic[]> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

$network = Get-VMHostNetwork Remove-VMHostNetworkAdapter $network.VirtualNic[0] -Confirm 

16.Set-VMHostNetworkAdapter

功能:配置指定的主机的网络适配器。

语法:

Set-VMHostNetworkAdapter -PhysicalNic <PhysicalNic[]> [-Duplex <String>] [-BitRatePerSecMb <Int32>] [-AutoNegotiate] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VMHostNetworkAdapter -VirtualNic <HostVirtualNic[]> [-Dhcp] [-IP <String>] [-SubnetMask <String>] [-Mac <String>] [-Mtu <Int32>] [-VMotionEnabled [<Boolean>]] [-FaultToleranceLoggingEnabled [<Boolean>]] [-ManagementTrafficEnabled [<Boolean>]] [-IPv6ThroughDhcp [<Boolean>]] [-AutomaticIPv6 [<Boolean>]] [-IPv6 <String[]>] [-IPv6Enabled [<Boolean>]] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)$vswitch = New-VirtualSwitch -VMHost 10.23.112.234 -Name VSwitch $nic = New-VMHostNetworkAdapter -VMHost 10.23.112.234 -PortGroup PortGroup -VirtualSwitch $vswitch -IP 10.23.123.234 -SubnetMask 255.255.254.0 Set-VMHostNetworkAdapter -VirtualNIC $nic -IP 10.23.112.245 -SubnetMask 255.255.255.0 -Mtu 4000

(2)

Get-VMHost Host | Get-VMHostNetworkAdapter -VMKernel | Set-VMHostNetworkAdapter -VMotionEnabled $true

(3)

Get-VMHostNetworkAdapter | where { $_.PortGroupName -eq "Service Console 1" } | Set-VMHostNetworkAdapter -IPv6Enabled $false

(4)

Get-VMHostNetworkAdapter | where { $_.PortGroupName -eq "Service Console 1" } | Set-VMHostNetworkAdapter -IPv6ThroughDhcp $true

(5)

Get-VMHostNetworkAdapter | where { $_.PortGroupName -eq "Service Console 1" } | Set-VMHostNetworkAdapter -AutomaticIPv6 $true

(6)

Get-VMHostNetworkAdapter | where { $_.PortGroupName -eq "Service Console 1" } | Set-VMHostNetworkAdapter -IPv6 $ipv6Address 

17.Add-VmHostNtpServer

功能:添加指定的NTP服务器到指定的主机的NTP服务器列表。

语法:

Add-VmHostNtpServer [-NtpServer] <String[]> [-VMHost] <VMHost[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Add-VmHostNtpServer -NtpServer "ntp-server-name.com" -VMHost $host

(2)

Add-VmHostNtpServer -NtpServer "192.168.1.5" -VMHost (Get-VMHost) 

18.Get-VMHostNtpServer

功能:检索指定的主机上的NTP服务器。

语法:

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

例子:

Get-VMHostNtpServer -VMHost 10.23.123.100 

19.Remove-VMHostNtpServer

功能:从指定的主机的NTP服务器列表中删除指定的NTP服务器。

语法:

Remove-VMHostNtpServer [-NtpServer] <String[]> [-VMHost] <VMHost[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

Remove-VmHostNtpServer -NtpServer 192.168.1.5 -VMHost $host –Confirm

(2)

Remove-VmHostNtpServer -NtpServer "old-ntp-server.com" -VMHost (Get-VMHost) -Confirm 

20.Test-VMHostSnmp

功能:测试主机的SNMP。

语法:

Test-VMHostSnmp [-HostSnmp] <VmHostSnmp[]> [<CommonParameters>]

例子:

Test-VMHostSNMP -HostSNMP (Get-VMHostSNMP) 

21.Get-VMHostSnmp

功能:获取主机的SNMP配置。

语法:

Get-VMHostSnmp [[-Server] <VIServer[]>] [<CommonParameters>]

例子:

Get-VMHostSNMP 

22.Set-VMHostSnmp

功能:更新主机的SNMP配置。

语法:

Set-VMHostSnmp [-HostSnmp] <VmHostSnmp[]> [-Enabled [<Boolean>]] [-Port <Int32>] [-ReadOnlyCommunity <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VMHostSnmp [-HostSnmp] <VmHostSnmp[]> [-Enabled [<Boolean>]] [-Port <Int32>] [-ReadOnlyCommunity <String[]>] [-TargetCommunity <String>] [-TargetPort <Int32>] [-TargetHost <String>] -RemoveTarget [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VMHostSnmp [-HostSnmp] <VmHostSnmp[]> [-Enabled [<Boolean>]] [-Port <Int32>] [-ReadOnlyCommunity <String[]>] -TargetCommunity <String> [-TargetPort <Int32>] -TargetHost <String> -AddTarget [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VMHostSnmp [-HostSnmp] <VmHostSnmp[]> [-Enabled [<Boolean>]] [-Port <Int32>] [-ReadOnlyCommunity <String[]>] [-RemoveTarget] -TrapTargetToRemove <TrapTarget> [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

(1)

$hostSNMP = Get-VMHostSNMP $hostSNMP = Set-VMHostSNMP $hostSNMP -Enabled:$true -ReadOnlyCommunity 'secret'

(2)

Get-VMHostSnmp | Set-VMHostSnmp -ReadonlyCommunity @() 

23.Get-VMHostStorage

功能:检索vSphere主机服务器上的存储。

语法:

Get-VMHostStorage [-VMHost] <VMHost[]> [-Refresh] [-RescanAllHba] [-RescanVmfs] [-Server <VIServer[]>] [<CommonParameters>]

例子:

(1)

Get-VmHostStorage -VMHost 10.23.112.234 -Refresh

(2)

Get-VMHostStorage | select -expandproperty scsilun | fl * 

24.Set-VMHostStorage

功能:配置一个主机存储。

语法:

Set-VMHostStorage -VMHostStorage <VMHostStorageInfo[]> -SoftwareIScsiEnabled [<Boolean>] [-WhatIf] [-Confirm] [<CommonParameters>]

例子:

Get-VMHostStorage 10.23.112.234 | Set-VMHostStorage -SoftwareIScsiEnabled $true   

你可能感兴趣的:(虚拟机,职场,休闲,vsphere,PowerCLI)