对于我们来说重命名ESXI主机的可能性不大,除非你在规划的时候未能够正常的规划这是有可能的。这里我们说一下关于ESXI主机名命名的操作方法:

esxi-rename


function Rename -VMHost  {
  
< #  
.SYNOPSIS Renames an ESXi server   
.DESCRIPTION The function will rename an ESXi 5.x server.
  The function follows VMware KB1010821
.NOTES Author: Luc Dekens  
.PARAMETER VMHost
  The ESXi server to be renamed
.PARAMETER Credential
  The credentials to connect to the ESXi 5.x server
.PARAMETER NewName
  The new FQDN 
.PARAMETER Location
  By default the ESXi server will stay in its current location.
  You can specify a Datacenter or Cluster for the newly named
  ESXi 5.x server.
.PARAMETER MaintenanceMode
  Although not required by KB1010821, by default the function
  places the ESXi 5.x server in maintenance mode, before doing
  the rename.
.PARAMETER DnsCheck
  When this switch is set , the function will first check if the
  new name for the ESXi host can be resolved with DNS.
.EXAMPLE
  PS > Rename -VMHost  -VMHost  $esx  -NewName  "newname.lucd.info"
#>
  
  [CmdletBinding()] 
  param(
    [PSObject] $VMHost ,
    [System.Management.Automation.PSCredential] $Credential ,
    [string] $NewName ,
    [PSObject] $Location ,
    [Switch] $MaintenanceMode  = $true ,
    [Switch] $DnsCheck
  )
  
  Process {
    if( $DnsCheck ){
      Try {
        [System.Net.Dns]::GetHostEntry( $NewName ).HostName | Out-Null
      }
      Catch {
        Write-Error  "No DNS entry for $NewName"
        return
      }
    }
    $vCenterName  = $global :DefaultVIServer.Name
      
    if( $VMHost  -is  [System.String]){
      $VMHost  = Get -VMHost  -Name  $VMHost
    }
    if( $Location ){
      if( $Location  -is  [System.String]){
        $Location  = Get -Inventory  -Name  $Location
      }
    }
    else {
      $Location  = $VMHost .Parent
    }
    if( $Location  -isnot  [VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl] -and
       $Location  -isnot  [VMware.VimAutomation.ViCore.Impl.V1.Inventory.DatacenterImpl]){
      Write-Error  "Location $($Location.Name) must be a datacenter or a cluster"
      return
    }
      
    if( $MaintenanceMode ){
      $previousState  = $VMHost .State
      Set -VMHost  -VMHost  $VMHost  -State  Maintenance | Out-Null
    }
    Set -VMHost  -VMHost  $VMHost  -State  Disconnected -Confirm : $false  |
    Remove -VMHost  -Confirm : $false  | Out-Null
  
    $esxServer  = Connect -VIServer  -Server  $VMHost .Name -Credential  $Credential
    $esxcli  = Get -EsxCli  -Server  $esxServer
    $esxcli .system.hostname. set ( $null , $NewName , $null )
    Disconnect -VIServer  -Server  $esxServer  -Confirm : $false
  
    Connect -VIServer  -Server  $vCenterName  | Out-Null
    $VMHost  = Add -VMHost  -Name  $NewName  -Location  $Location  -Credential  $Credential  -Force  -Confirm : $false
  
    if( $MaintenanceMode ){
      Set -VMHost  -VMHost  $VMHost  -State  $previousState  -Confirm : $false  | Out-Null
    }
  }
}
注释

行40-48:该函数会检查新的主机名就可以解决。如果不是在函数返回。

行51-53:廉价对象通过名称(OBN)实施

行54-66:在ESXi的将被添加到在$位置变量指定的位置。这可以是一个数据中心或集群。如果没有位置值传递,将主机添加到同一位置,这是重命名之前。

行68-71:虽然不是必需的(参见KB1010821),将其改名为主机处于维护模式的默认。切换到维护模式,将所有的VMotion虚拟机到集群中的其他节点。

行72-73:在ESXi主机断开,并从vCenter删除。

行75-78:该函数使用的Get-ESXCLI cmdlet将能够调用的命名方法。请注意,在这一点上该函数将关闭的vCenter连接,并直接连接到ESXi主机。

行80-81:重命名后,将ESXi主机添加到vCenter在它的老位置,或者被显式地在函数调用中指定的位置。

行83-85:当需要时,ESXi主机取出的维护模式,并放置在模式它是在最初。

用法示例

使用这个功能是相当简单的。

在它的最简单的形式,您所提供的VMHOST,新名称和凭据。

$oldName = "esx1.local.test"
$newName = "esx2.local.test"
$username = "root"
$pswd = "password"
$pswdSecure = ConvertTo-SecureString -String $pswd -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$pswdSecure
Rename-VMHost -VMHost $oldName -NewName $newName -Credential $cred

ESXi主机,称为esx1.local.test将被重新命名为esx2.local.test。该函数将测试,如果新名称是解析的DNS,它会放置ESXi主机的维护模式重命名之前完成。

请注意,我只测试了这个功能上的ESXi 5.x主机。