PowerCLI

 View Only
Expand all | Collapse all

How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

  • 1.  How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Apr 18, 2017 01:24 PM

    Hi!

    There are examples on the internet on how to get this setting, like

    (Get-VM -Name "a-vm-name" | Get-NetworkAdapter).ExtensionData.UptCompatibilityEnabled

    but there is none on how to set it. I know I could use Onyx but my vCenter has overtaken it (6.0 --> 6.5). :smileyhappy: Maybe I can get a quicker answer here...

    Thanks

    Gregor



  • 2.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter
    Best Answer

    Posted Apr 18, 2017 05:43 PM

    Try like this

    $vmName = 'VM1'

    $nicName = 'Network Adapter 1'

    $directPath = $false   # or $true to enable Direct Path IO

    $vm = Get-VM -Name VM1

    $nic = Get-NetworkAdapter -VM $vm -Name $nicName

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

    $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::edit

    $dev.Device = [VMware.Vim.VirtualDevice]$nic.ExtensionData

    $dev.Device.UptCompatibilityEnabled = $directPath

    $spec.DeviceChange += $dev

    $vm.ExtensionData.ReconfigVM($spec)



  • 3.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Apr 20, 2017 02:04 PM

    Is there a way to achieve this in v6 as it looks like "'UptCompatibilityEnabled'" does not exist :(

    Thanks



  • 4.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Apr 20, 2017 02:46 PM

    Ignore my question! I finally found the answer. It's an advanced option, so I could get its status with:
    Get-VM MyVM | Get-AdvancedSetting | Where-Object {$_.Name -like "ethernet*.uptCompatibility"}

    And could set it like this:

    Get-VM MyVM| Get-AdvancedSetting | Where-Object {$_.Name -like "ethernet*.uptCompatibility"} | Set-AdvancedSetting -Value "False" -Confirm:$false

    Note that I'm using "ethernet*.uptCompatibility" to catch all NICs



  • 5.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Apr 21, 2017 07:05 AM
    Arggg! Also what I posted above seems not to be entirely true. In fact, I see that option enabled on multiple VMs but DirectPath I/O is disabled. I'm lost now!


  • 6.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Apr 21, 2017 07:17 AM

    I'm not sure what you are seeing.

    On the UptCompatibilityEnabled property, that was introduced in vSphere API 6.0, so the script above should work for vSphere 6.x



  • 7.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Apr 21, 2017 07:41 AM
    My fault! I just realised I was running an ancient version of powercli. Now I can see also ExtensionData.UptCompatibilityEnabled. 


  • 8.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Oct 06, 2017 08:06 AM

    Hi Simsync,

    I ran into the same problem running in pcli 5.5, could you please share which version of PCLi you updated to to get this working?

    thanks in advance!!



  • 9.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Jul 05, 2018 07:48 PM

    Great script, thank you!

    Do you have a version of it to disable DPIO on multiple VM's?  I need to apply this fix to over 300 VM's due to this bug being present when a template was created.



  • 10.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Jul 05, 2018 08:25 PM

    You can run the code in a ForEach loop.

    In the code below I just do a Get-VM, but you can make the selection more specific by using a mask or even an external file to provide the names of the VMs.

    $nicName = 'Network Adapter 1'

    $directPath = $false   # or $true to enable Direct Path IO

    foreach($vm in Get-VM){

       $nic = Get-NetworkAdapter -VM $vm -Name $nicName

       $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

       $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

       $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::edit

       $dev.Device = [VMware.Vim.VirtualDevice]$nic.ExtensionData

       $dev.Device.UptCompatibilityEnabled = $directPath

       $spec.DeviceChange += $dev

       $vm.ExtensionData.ReconfigVM($spec)

    }



  • 11.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Jul 05, 2018 08:59 PM

    Thank you LucD, added in a VM mask and tested and it works perfectly!

    I was struggling to put the code into the ForEach loop properly and turns out I was just massively over complicating it.

    Thanks for your help!  Much appreciated! :)



  • 12.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted May 20, 2019 08:46 AM

    Hello LucD,

    The code provided doesn't throw any error. However when I double check the vmx file the result is not applied and the previous value persist.

    I have copy/paste your code, and to verify the value of "$dev.Device.UptCompatibilityEnabled" I collect it before and after the config is applied.

    I have also check in the vmx file and the value for the UptCompatibilityEnabled persist.

    The line $vm.ExtensionData.ReconfigVM($spec) looks to not apply the config to the vmx file.

    Is anyone else who notice that behavior ?

    I am on ESXi 6.5 U2

    Thanks !

    Regis B



  • 13.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted May 20, 2019 08:53 AM

    The settings in the VMX are not updated immediately.

    Was the VM powered off when you ran the script?



  • 14.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Mar 11, 2021 03:52 PM

    i know it is an old post, but I have a lot of vms , with DirectPath I/O enabled. when I have tried to run the script the $dev.Device variable returns Null.

    any idea?



  • 15.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Mar 11, 2021 04:45 PM

    Since that value comes from the $nic variable, is there anything in there?



  • 16.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Mar 14, 2021 11:04 AM

    but it does bring the network adapter  1. 



  • 17.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Mar 14, 2021 12:26 PM

    I would need to see the code you are using.



  • 18.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Mar 14, 2021 01:14 PM

    please see below \

    $directPath = $false
    $nic = (Get-NetworkAdapter -VM $VMname).Name
    write-host $nic -ForegroundColor Cyan
    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
    write-host $spec -ForegroundColor Cyan
    $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
    write-host $dev -ForegroundColor Cyan
    $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::edit
    write-host $dev.Operation -ForegroundColor Cyan
    $dev.Device = [VMware.Vim.VirtualDevice]$nic.ExtensionData
    write-host $dev.Device  -ForegroundColor Cyan
    $dev.Device.UptCompatibilityEnabled = $directPath
    $spec.DeviceChange += $dev
    $VMname.ExtensionData.ReconfigVM($spec)

     



  • 19.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Mar 14, 2021 02:08 PM

    Does that VM have more than 1 vNIC?
    In that case, that snippet will not work I'm afraid.

    Also, there are a couple of errors in there.
    You populate the $nic variable with the name of the vNIC(s).
    Then you use $nic.ExtensionData, which doesn't exist.



  • 20.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Aug 24, 2018 12:26 AM

    Anyone else having similar issue when trying to run this against a list of VMs in a text file?  Using the script below...

    $nicName = 'Network Adapter 1'

    $directPath = $false   # or $true to enable Direct Path IO

    $vmlist = Get-Content C:\Temp\VmList.txt

    foreach($vm in $vmlist){

       $nic = Get-NetworkAdapter -VM $vm -Name $nicName

       $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

       $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

       $dev.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::edit

       $dev.Device = [VMware.Vim.VirtualDevice]$nic.ExtensionData

       $dev.Device.UptCompatibilityEnabled = $directPath

       $spec.DeviceChange += $dev

       $vm.ExtensionData.ReconfigVM($spec)

    }

    I receive the following error...

    You cannot call a method on a null-valued expression.

    At E:\Scripts\DirectPathIO.ps1:13 char:4

    +    $vm.ExtensionData.ReconfigVM($spec)

    +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

        + FullyQualifiedErrorId : InvokeMethodOnNull

    I can't see any undeclared variables but doing this one by one is out of the question with over 350 VMs affected.  Any help would be appreciated.  Thanks.



  • 21.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Aug 24, 2018 04:11 AM

    Could it be that you have a blank line in the file? At the end perhaps?



  • 22.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Aug 24, 2018 05:16 AM

    Confirmed that there's no blank lines in the text file. 

    I've been testing with only one or two server names in VmList.txt, no spaces or blank lines in the file.



  • 23.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Aug 24, 2018 06:11 AM

    Ok, I see the issue.

    You are calling the ReconfigVM method on a [string] object.
    Change line 3 to

    $vmlist = Get-VM -Name (Get-Content C:\Temp\VmList.txt)



  • 24.  RE: How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

    Posted Aug 24, 2018 06:16 AM

    That was it... thanks for your help!