VMware Cloud Community
GregorSm
Contributor
Contributor
Jump to solution

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

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). Smiley Happy Maybe I can get a quicker answer here...

Thanks

Gregor

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

23 Replies
LucD
Leadership
Leadership
Jump to solution

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)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

simsync
Enthusiast
Enthusiast
Jump to solution

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

Thanks

Reply
0 Kudos
simsync
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
simsync
Enthusiast
Enthusiast
Jump to solution

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!
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
simsync
Enthusiast
Enthusiast
Jump to solution

My fault! I just realised I was running an ancient version of powercli. Now I can see also ExtensionData.UptCompatibilityEnabled. 
Reply
0 Kudos
YashvM
Contributor
Contributor
Jump to solution

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!!

Reply
0 Kudos
nickurquhart
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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)

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
nickurquhart
Contributor
Contributor
Jump to solution

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! 🙂

Reply
0 Kudos
Brewy
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Brewy
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Brewy
Contributor
Contributor
Jump to solution

That was it... thanks for your help!

Reply
0 Kudos
rebaudin
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The settings in the VMX are not updated immediately.

Was the VM powered off when you ran the script?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
plaman
Enthusiast
Enthusiast
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos