You will have to define these parameters on the function, as parameters
Function Set-WinVMIP ($VM, $IP, $SNM, $GW, $GfU, $GfP){
...
Invoke-VMScript -VM $VM -GuestUser $GfU -GuestPassword $GfP -ScriptType bat -ScriptText $netsh
}
and then you call the function for example like this (positional parameters)
Set-WinVMIP $VM $_.IP $SNM $GW $GU $GP
You can also use named parameters
Set-WinVMIP $VM $_.IP $SNM $GW -GfU $GU -GfP $GP