Get-VM -Name cli | New-SerialPort -port 5555
Created
January 11, 2020 16:16
-
-
Save TrooperT/52776ffa2d559a4b37fbd7915dd1ed69 to your computer and use it in GitHub Desktop.
Pipeable Addition of Serial port to VMware VM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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