Skip to content

Instantly share code, notes, and snippets.

@TrooperT
Created January 11, 2020 16:16
Show Gist options
  • Select an option

  • Save TrooperT/52776ffa2d559a4b37fbd7915dd1ed69 to your computer and use it in GitHub Desktop.

Select an option

Save TrooperT/52776ffa2d559a4b37fbd7915dd1ed69 to your computer and use it in GitHub Desktop.
Pipeable Addition of Serial port to VMware VM

Get-VM -Name cli | New-SerialPort -port 5555

Function New-SerialPort {
Param (
[Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True)]
$Name,
[Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True)]
$Port
)
Process {
$VMDevSpec = New-Object VMware.Vim.VirtualDeviceConfigSpec
$VMDevSpec.Operation = "add"
$VMDevSpec.device = New-Object VMware.Vim.VirtualSerialPort
$VMDevSpec.device.key = -1
$VMDevSpec.device.backing = New-Object VMware.Vim.VirtualSerialPortURIBackingInfo
$VMDevSpec.device.backing.direction = "server"
$VMDevSpec.device.backing.serviceURI = "telnet://:$Port"
$VMDevSpec.device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo
$VMDevSpec.device.connectable.connected = $true
$VMDevSpec.device.connectable.StartConnected = $true
$VMDevSpec.device.yieldOnPoll = $true
$VMSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$VMSpec.DeviceChange += $VMDevSpec
$VM = Get-VM -Name $Name
$VM.ExtensionData.ReconfigVM_Task($VMSpec)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment