I'm just starting out with the very basics of Powershell scripting and am looking at creating a script to one set of instructions then restart and continue running the rest of the script.
The first part of the script makes changes to the registry, firewall and ip/dns settings, then renames the server(win2012). Then a restart is needed to continue with the installation of ad domain services and forest creation.
I've had a look around but don't really understand the concepts. Can anyone recommend a very easy way to implement the reboot and resume.
The most easiest way is already built-in into Windows. There are a bunch of registry keys, which you can use to configure some action that is to be executed once after a reboot.
For your use case, you probably want to use one of the
RunOnce
keys. As always, the exhaustive documentation can be found in the MSDN pages, here's the essence of it:So basically the only thing you need to do is to create an entry under that reg key which calls powershell and passes your script as argument.
Using
RunOnce
below HKLM would run the script for any user, but requires elevated rights to write the registry entry. In contrast, HKCU is bound to the current user, but does not require additional permissions.For reboot, simply call the Windows
shutdown
command, e.g.To automatically resume a powershell workflow after reboot/crash using task scheduler see my detailed stackoverflow answer here: https://stackoverflow.com/a/31100397/1487851