Something like this?
Import-Csv deploy.csv -UseCulture | %{ function UpdateVMSettings { Write-Host "Changing Portgroup and virtual Hardware..." Get-OSCustomizationSpec $_.Customization | -MemoryMB $_.MemoryMB -NumCpu $_.NumCpu -Confirm:$false Get-OSCustomizationSpec $_.Customization | Get-OSCustomizationNicMapping | where { $_.Position -eq '1'} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_."IP Address" -SubnetMask 255.255.255.0 -DefaultGateway $_."GW" -Confirm:$false Get-OSCustomizationSpec $_.Customization | Get-OSCustomizationNicMapping | where { $_.Position -eq '2'} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_."Maint IP Address" -SubnetMask 255.255.0.0 -DefaultGateway $_."GW" -Confirm:$false Get-OSCustomizationSpec $_.Customization | Get-NetworkAdapter | Where {$_.NetworkName -eq 140 } |Set-NetworkAdapter -NetworkName $VLAN -Confirm:$false } $vm=New-VM -Name $_."Server Name" -Template $_.Template -Host $_."Esx Host" ` -Datastore $_.Datastore -OSCustomizationSpec $_.Customization ` -Confirm:$false -RunAsync }