Happy New Year All
I am stuck with below script for removing vNIC from multiple machines, it works fine for one VM (got it from one of Luc's older posts). There is no space at the end of VM name in the text file.
$VMS = Get-Content "c:\servers.txt"
$vm = Get-VM $VMS
Foreach ($vm in $VMS)
{
$nic = $vm.ExtensionData.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq "Network adapter 2"}
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
$dev.operation = "remove"
$dev.Device = $nic
$spec.DeviceChange += $dev
$vm.ExtensionData.ReconfigVM($spec)
}
I get this when I run it (there are 2 VM names in the text file)
You cannot call a method on a null-valued expression.At line:11 char:1
+ $vm.ExtensionData.ReconfigVM($spec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:11 char:1
+ $vm.ExtensionData.ReconfigVM($spec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Thank you ...