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.