I'm building a script which does the following things
Most steps seem to work, I only get stuck on step 4.
I use the following line.
Invoke-Command -FilePath C:\Support\createdomain.ps1 -VMName TEMPLATE-DC
Which asks for the credentials of the VM, and it goes on and do the stuff. Until I get to the reboot.
Restart-Computer -Wait -For PowerShell -Timeout 300 -Delay 2
I also tried to just have the following, this restarts the VM but also stops the Powershell session and does not run the Start Sleep
Restart-Computer -Force
Start-Sleep -s 300
So my question is: how can I run a powershell script on a remote machine, in this case a VM. And do a reboot and wait until it is rebooted to resume the script?
This is the error I get
The background process reported an error with the following message: "The Hyper-V socket target process has ended.".
+ CategoryInfo : OperationStopped: (TEMPLATE-DC:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
+ PSComputerName : TEMPLATE-DC
I would recommend breaking that script up into three pieces.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.