E
E
Evgeny Ferapontov2016-09-22 02:34:19
PowerShell
Evgeny Ferapontov, 2016-09-22 02:34:19

How to resume running a PowerShell script after a computer restart?

You often need to deploy new Hyper-V hosts. To make my work easier and protect myself from human errors, I decided to write a script similar to the one described in the book "Windows Server 2012 Hyper-V Installation and Configuration Guide": the script renames the host, enables RDP, raises the Hyper-V and FC roles, creates virtual switches, bla -blah blah. In short, a lot of work and 2 reboots. It is necessary to somehow continue the execution of the script from the place where it was interrupted by the reboot after turning on the same Hyper-V. Otherwise, you have to enter a lot of passwords and click a lot, which is not feng shui.
Somewhere I heard that Server Manager since WS 2012 works entirely on PowerShell. It successfully continues installing and configuring roles even after a reboot, I want the same. How?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Ethril, 2016-09-22
@Ethril

The first option, obvious and crooked, is to farm with a scheduler and semaphore files.
The second, more elegant option is to master remoting, run scripts on another machine, clinging to the target machine through Invoke-PSSession. The ultimate development of the second option is to master ansible (+ playbooks), deploy an automation server, run all automation tasks on it.

E
Eugene, 2016-09-22
@yellowmew

as an alternative - study the powershell desired state configuration and configure the machine www.powershellgallery.com/packages/xHyper-V/3.5.0.0 (there are other modules, you need to dig)
However, pay attention to Ethril 's answer - it may go easier

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question