Hi,
I have a number of machines that were set with a static IP, Subnet, Gateway and DNS settings. For some reason, we have found that the previous gateway provided by DHCP before setting static settings, has remained as an alternate gateway on the network interface for these machines.
This means that on occassion, we are unable to connect to these machines remotely, as Windows decides to use the alternate gateway which is on a totally different subnet to the interface IP.
What I'd like to do, is run a script I've written to remotely delete the default routes, and recreate them using the correct gateway IP.
My query is, when running Invoke-Command, is everything from the ScriptBlock transfered to the remote machine at the start of the command, or does the parent script execute each part of the script block one command at a time?
Reason for asking, is that if it sends the entire script block, it should be unaffected by network drops right?
However, if the parent script runs one command at a time, then I would assume as soon as the default routes are deleted, the following commands to create new routes would fail, as the machine will have lost connectivity due to no longer having any default routes?
Is there a way I can have it send all the commands in the script block first (assuming this is not the current behaviour), before executing them? Not sure if that's what the "-AsJob" switch does?
Cheers
James