CSV

I am trying to pull info from a CSV and use invoke-vmscript to change ip addresses on a specific network adapter (filtered by interface index).
But am receiving the following error
New-NetIPAddress : Cannot bind argument to parameter 'IPAddress' because it is an empty string.
Set-DnsClientServerAddress : Cannot validate argument on parameter 'InterfaceIndex'. The argument is null. Provide a | valid value for the argument, and then try running the command again.

I have a csv file headered as above
`$vms = Import-CSV "C:\\Scripts\\servers.csv"
$GC = $Host.UI.PromptForCredential("Please enter credentials", "Enter Guest credentials for VM", "xxxx", "")
foreach ($vm in $vms){
$VMName = $vm.Name
$IP = $vm.IP
$SNM = $vm.SubnetMask
$GW = $vm.Gateway
$DNS1 = $vm.DNS1
$DNS2 = $vm.DNS2
$adapter = Invoke-VMScript -VM $VMname -ScriptType Powershell -ScriptText '(Get-NetAdapter -InterfaceDescription Vm\*).ifindex' -GuestUser xxx -GuestPassword xxx
Write-Host "Setting IP address for $VMname..." -ForegroundColor Yellow
Sleep -Seconds 60
$ip1 = Invoke-VMScript -VM $VMname -ScriptType Powershell -ScriptText '(New-NetIPAddress -InterfaceIndex $adapter -IPAddress $IP -PrefixLength 24 -DefaultGateway $GW)'
$ip2 = Invoke-VMScript -VM $VMname -ScriptType Powershell -ScriptText '(Set-DnsClientServerAddress -InterfaceIndex $adapter -ServerAddresses ("$DNS1","$DNS2"))'
Set-DnsClientServerAddress -InterfaceIndex $adapter -ServerAddresses ("$DNS1","$DNS2")
Invoke-VMScript -VM $VMname -GuestCredential $GC -ScriptType Powershell -ScriptText $ip1
Invoke-VMScript -VM $VMname -GuestCredential $GC -ScriptType Powershell -ScriptText $ip2
Write-Host "Setting IP address completed." -ForegroundColor Green
Sleep -Seconds 20
(\[WMIClass\]"\\$vmname\\ROOT\\CImv2:Win32_Process").Create("cmd.exe /c ipconfig /registerdns")
}`
thing is if i run the variable $ip i get the ip provided back to me
also if i run these commands directly on a host it works ok
connect-viserver xxx
$vms = Import-CSV "\\in1grascm001\Source_Files\New-Nicservers.csv"
$adapter = (get-netadapter -InterfaceDescription Vm*).IfIndex
foreach ($vm in $vms){
$IP = $vm.ip
$GW = $vm.Gateway
New-NetIPAddress -InterfaceIndex $adapter -IPAddress $ip -PrefixLength 24 -DefaultGateway $vm.Gateway
Set-DnsClientServerAddress -InterfaceIndex $adapter -ServerAddresses ("x.x.x.x","x.x.x.x")
Sleep -Seconds 20
([WMIClass]"\\$vmname\ROOT\CImv2:Win32_Process").Create("cmd.exe /c ipconfig /registerdns")
}