'Remote ipconfig /release issue with powershell

I have a powershell script that does an ipconfig /release and /flushdns then a shutdown command for my VMs. I do this before creating a snapshot. The script works but it doesn't work for multiple computers in a CSV because as soon as the ipconfig /release occurs it gets stuck on the same machine and waits for it to reconnect. Is there a way to break the script so that it forces to go to the next machine? It's doing the shutdown as well just not moving onto next machine. Code:

$Machines | foreach-object {
    
    write-host $_.MachineName
    
    Get-Service -Computer $_.MachineName -Name CcmExec | Stop-Service
    Get-Service -Computer $_.MachineName -Name CcmExec | Set-Service -StartupType Disabled
    Get-Service -Computer $_.MachineName -Name CcmExec
    Invoke-Command -Computer $_.MachineName -ScriptBlock {
    Add-LocalGroupMember -Group "Administrators" -Member $Using:Username
    Get-ScheduledTask -TaskPath "\Microsoft\Configuration Manager\" | Disable-ScheduledTask
    cmd.exe /c ipconfig /flushdns
    cmd.exe /c ipconfig /release
    cmd.exe /c shutdown -f -s -t 25
      
    } 
}


Solution 1:[1]

Just as I was laying down to go to sleep last night, this popped into my head. Why, how, I don't know!

What happens if you change

    cmd.exe /c ipconfig /flushdns
    cmd.exe /c ipconfig /release
    cmd.exe /c shutdown -f -s -t 25

to

    cmd.exe /c shutdown -f -s -t 300
    cmd.exe /c ipconfig /flushdns
    cmd.exe /c ipconfig /release

?

I would think any termination of the remote ran scriptblock would result in the caller continuing on to do other work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1