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>