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.

Revisions

  1. TrooperT created this gist Jan 11, 2020.
    27 changes: 27 additions & 0 deletions New-SerialPort.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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)
    }
    }
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Get-VM -Name cli | New-SerialPort -port 5555