Saturday 20 July 2013

Add Serial port to VM through GUI or powerCLI

Goto ESXi host on vCenter ->Configuration -> Security Profile ->Firewall Properties.














The Goto VM where you want to enable the serial connection à
Right click -> Edit Settings -> Hardware -> Add -> Serial Port

 













Reference:





PowerCLI script to do create serial port. Although Firewall settings on esxi server has to be done manually.


# Adds the base cmdlets
Add-PSSnapin VMware.VimAutomation.Core
# This script adds some helper functions and sets the appearance. You can pick and choose parts of this file for a fully custom appearance.
. "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"

Function New-SerialPort
{
 Param(
   [string]$vmName,
   [string]$prt
) #end
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.operation = "add"
$dev.device = New-Object VMware.Vim.VirtualSerialPort
$dev.device.key = -1
$dev.device.backing = New-Object VMware.Vim.VirtualSerialPortURIBackingInfo
$dev.device.backing.direction = "server"
$dev.device.backing.serviceURI = "telnet://:$prt"
$dev.device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo
$dev.device.connectable.connected = $true
$dev.device.connectable.StartConnected = $true
$dev.device.yieldOnPoll = $true

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.DeviceChange += $dev

$vm = Get-VM -Name $vmName
$vm.ExtensionData.ReconfigVM($spec)

}




  1. Power OFF your VM
  2. open PowerCLI 
  3. New-SerialPort <vmname> <telnet port number>
  4. Power ON your vm
  5. telnet <esxi IP> <port number>

5 comments:

  1. Nice article. I will make it with SEC software by Eltima. Do you know it?

    ReplyDelete
  2. i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future..
    vmware courses london

    ReplyDelete
  3. Is it possible to add serial port using vCLI commands instead of PowerCLI?
    eg. commands directly from ESX shell or from vCLI packages

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. I used this as base for my own using named pipe:

      #This scripts adds COM ports to a VM in vsphere cluster

      $cred = Get-Credential
      $vcentername = Read-Host -Prompt 'Input the vcenter DNS Name'
      $vmname = Read-Host -Prompt 'Input the VM Name for adding COM ports'
      $amountofports = Read-Host -Prompt 'Input the amount of COM ports you want to add (max 32 total)'


      Connect-VIServer -Server $vcentername -Credential $cred
      $vm = Get-VM -Name $vmName

      if($vm.PowerState -eq 'PoweredOn') {
      Write-Host 'VM must be turned off for the serial ports to be added'
      Stop-VM -VM $vm -Confirm:$true
      }


      for (($i = 1); $i -le $amountofports; $i++)
      {
      Write-Host 'Adding port number ' $i
      New-SerialPort $vmname 1
      }


      Function New-SerialPort
      {
      Param(
      [string]$vmName
      #[string]$prt
      ) #end
      $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
      $dev.operation = "add"
      $dev.device = New-Object VMware.Vim.VirtualSerialPort
      $dev.device.key = -1
      $dev.device.backing = New-Object VMware.Vim.VirtualSerialPortPipeBackingInfo
      $dev.device.backing.endpoint = "server"
      $dev.device.backing.pipeName = "\\.\pipe\"

      $dev.device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo
      $dev.device.connectable.connected = $true
      $dev.device.connectable.StartConnected = $true
      $dev.device.yieldOnPoll = $true

      $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
      $spec.DeviceChange += $dev

      $vm.ExtensionData.ReconfigVM($spec)

      }

      Delete