Execute script, restart and resume

Hi all,

I have a script that executes various commands for initial configuration of Windows server and would like to reboot at a specific point and then resume from that point onwards to the end.

Is there any way to do that?
Thank you.

You could use PowerShell Workflow

1 Like

Thank you Olaf. Will go through the documentation.

Hello @Olaf .
So i went through the documented and initiated a remote pssession with my VM from my host, within PS ISE.
Then i denoted the below function. When i hit enter the results are showing that the powershell runs both WMI-Object commands and it says an error that fails to restart because there are other users logged on to the computer.
Any thoughts of what am i doing wrong?
Thank you.

workflow test-restart {

 Get-WmiObject -Class Win32_ComputerSystem

 Restart-Computer -Wait -PSComputerName xxxxxxxxxxx

 Get-WmiObject -Class Win32_OperatingSystem

}

If you give a shit on other users logged on to the remote computer and their potentially unsaved work you can use the parameter -Force to force an immediate restart of the remote computer. :wink: :smiley:

1 Like

Yes I get your point :stuck_out_tongue: even though I am now just testing it on my VM where I am the only user logged on, so this seems strange to me. And even with the force restart, when it gets back online, the connections of the PSSession is dropped, so i guess something is really wrong.
But thank you for your reply :slight_smile:

If you’re logged in with an interactivce session and you try to remotely reboot this computer the remote command does actually not see who’s logged on - only that there is someone logged on … therefor the “hesitation”. :wink: