Reboot a computer and automatically restart a script

6 views
Skip to first unread message

Andrea 'ML' Suatoni

unread,
Aug 22, 2023, 10:30:45 AM8/22/23
to ntpowe...@googlegroups.com

Hi, looking for some advice on the above.

 

One of our environments is a closed network, no Internet, no DHCP, no SCCM available. Setting up a Windows server consists generally in running a bunch of (hardening) scripts, network configuration, domain joining, and optionally depending on the use adding roles from IIS up to Hyper-V+ Failover Cluster. This is quite tedious, prone to errors, with operators hanging on waiting for the various needed reboots to login again, open a PowerShell, and start the next scripts. And when the server being setup is physical, it takes even more time.

 

We are thinking on a way to automate all of these. I have searched for ideas, and I’ve seen hints here and there. One suggests to use PowerShell workflows, but to be honest they seems more geared to use DSC on remote computers, which is not our case. Others suggest to use the task scheduler, or the RunOnce key. The fact is: there are reboots that may be needed even before a network connection is configured because the network layer is being altered (when installing the Hyper-V role, for instance), others require to reboot after having joined a domain, and joining the domain hampers (due to GPOs) any kind of auto-login set in place to complete the script (a possible solution to this last issue could be to temporarily put the computer in a OU where GPOs are not applied, but there may be other implications)

 

Do you have any experience that you can share here?

 

Thanks!

Andrea

Michael B. Smith

unread,
Aug 22, 2023, 10:49:10 AM8/22/23
to ntpowe...@googlegroups.com

You build a state machine. I’ve done this with MDT and SCCM and standalone deployments for years.

 

All you need is a PS script and a network deployment location and the RunOnce key.

 

Just remember that each state does one thing only!

 

$state = getState

if( $state -eq $state_1 )

{

    Push-Location 'Apps\Copy-Fonts'

    doPowerShell copy-fonts.ps1

    Pop-Location

 

    setState $state_2

}

 

$state = getState

if( $state -eq $state_2 )

{

    Push-Location 'Apps\Google Chrome'

    $val = doMSI 'msiexec.exe' @( '/i', 'GoogleChromeStandaloneEnterprise64.msi', '/qn', '/norestart' )

    Pop-Location

 

    setState $state_3

    checkForReboot $val

}

 

$state = getState

if( $state -eq $state_3 )

{

    Push-Location 'Apps\Mozilla Firefox'

    $val = doBinary 'FirefoxSetup.exe' @( '/S', '/DesktopShortcut=true', '/MaintenanceService=true' )

    Pop-Location

 

    setState $state_4

    checkForReboot $val

}

 

 

Thanks.

 

Regards,

Michael B. Smith

Managing Consultant

Smith Consulting, LLC

--
You received this message because you are subscribed to the Google Groups "ntpowershell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ntpowershell...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/AS8P195MB2439F5F4B84B42E5B17DAD88C41FA%40AS8P195MB2439.EURP195.PROD.OUTLOOK.COM.

Andrea 'ML' Suatoni

unread,
Aug 22, 2023, 11:23:16 AM8/22/23
to ntpowe...@googlegroups.com

Michael,

 

Thanks for your answer. We used to deal with MDT in the past but on workstations. Servers are a different beast: different models/generations/vendors, each one with its own set of drivers/vendor software. Think about a HPE Blade with FC mezzanine, LUNs are not generally available until you load the drivers, or are shown multiple times until you install the MPIO feature (which requires another mandatory reboot) and sometime you need also some software from your SAN storage vendor, too. Hyper-V role adds a network layer, and enforces a reboot, your initial network config has to be redone after the reboot. Failover Cluster can be installed before joining a domain (and requires another reboot), but the node cannot be added to the cluster until the host is joined.

 

I could go on with more examples. Your excerpt comes from what? Custom MDT task step?

 

Thanks,

Andrea

Michael B. Smith

unread,
Aug 22, 2023, 11:28:30 AM8/22/23
to ntpowe...@googlegroups.com

Same thing still applies. Yes, a server is more complicated, but you just need more steps.

 

My example was taken out of a script for a RDP session host.

Reply all
Reply to author
Forward
0 new messages