PowerCLI

 View Only
  • 1.  adding serial port

    Posted Jul 08, 2016 02:06 PM

    I'm trying to add a serial port to a vm to point to the ESXI hosts physical serial port. I have to repeat this about a hundred times, so looking to script this. I can find scripts for doing this with other types of serial ports, but been unable to adapt this to a physical serial port mapped through.

    Thanks



  • 2.  RE: adding serial port
    Best Answer

    Posted Jul 09, 2016 05:18 AM

    Can you try like this ?

    You will have to check the "devicename"

    $vmName = <guestname>

    $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.VirtualSerialPortDeviceBackingInfo

    $dev.device.backing.deviceName = '/dev/char/serial/uart0'

    $dev.device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

    $dev.device.connectable.startConnected = $true

    $dev.device.connectable.allowGuestControl = $true

    $dev.device.connectable.connected = $true

    $dev.device.yieldOnPoll = $true

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.DeviceChange += $dev

    $vm = Get-VM -Name $vmName

    $vm.ExtensionData.ReconfigVM($spec)



  • 3.  RE: adding serial port

    Posted Jul 11, 2016 11:53 AM

    Thank you SO MUCH!!

    I struggled with the syntax - haven't got my head around these registry type settings at all!

    Debbie



  • 4.  RE: adding serial port

    Posted Oct 19, 2023 09:02 AM

    Hi LucD,

    Can we add serial port to any VM with physical device set as "'/dev/char/serial/uart0'" with this script?
    Manually it requires to perform this on vcenter if the vm is power-off, and if we have for example 300 VMs and run this script to add serial port all of them, will it work for us?



  • 5.  RE: adding serial port

    Posted Oct 19, 2023 09:27 AM

    Afaik the VM is required to be powered off for this.



  • 6.  RE: adding serial port

    Posted Oct 19, 2023 09:37 AM

    Thanks for this script, it is worked on vCenter 7.0u3



  • 7.  RE: adding serial port

    Posted Oct 19, 2023 02:24 PM

    And what if we select "Use Output File" and want to set local datastore or a storage from a datastore cluster where the vms have access to?
    How can we modify this script?

    VMwareGeek__1-1697725418117.png

     



  • 8.  RE: adding serial port

    Posted Oct 19, 2023 02:36 PM

    In that case, the Backing should become a VirtualSerialPortFileBackingInfo instead of a VirtualSerialPortDeviceBackingInfo.
    That object will allow you to specify the Datastore and FileName properties



  • 9.  RE: adding serial port

    Posted Oct 19, 2023 04:08 PM

    So in this case will it be like below?

     

    $vmName = testvm1

     

    $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.VirtualSerialPortFileBackingInfo

    $dev.device.backing.deviceName = '[datastore1 (136)] /testvm1/TEST'

    $dev.device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

    $dev.device.connectable.startConnected = $true

    $dev.device.connectable.allowGuestControl = $true

    $dev.device.connectable.connected = $true

    $dev.device.yieldOnPoll = $true

     

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.DeviceChange += $dev

     

    $vm = Get-VM -Name $vmName

    $vm.ExtensionData.ReconfigVM($spec)



  • 10.  RE: adding serial port

    Posted Oct 19, 2023 04:11 PM

    No, in this case, there is no DeviceName property, only a Datastore and FileName property.



  • 11.  RE: adding serial port

    Posted Oct 19, 2023 04:13 PM

    And how should I modify the script?

    $vmName = testvm1
    $filePath = "[datastore1 (136)] /testvm1/TEST.txt"

    $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.VirtualSerialPortFileBackingInfo

    $dev.device.backing.fileName = $filePath

    $dev.device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

    $dev.device.connectable.startConnected = $true

    $dev.device.connectable.allowGuestControl = $true

    $dev.device.connectable.connected = $true

    $dev.device.yieldOnPoll = $true

     

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.DeviceChange += $dev

    $vm = Get-VM -Name $vmName

    $vm.ExtensionData.ReconfigVM($spec)



  • 12.  RE: adding serial port

    Posted Oct 19, 2023 04:57 PM

    Yes, like that