Mid of the script restart the machine and continue the script. RRS feed

  • Question

  • Hi,

    Im using below mentioned script for hostname change & domain join automatically.

    • $ComputerName = Get-WmiObject Win32_ComputerSystem 
      [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null 
      $name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Desired Computer Name ")

      "Restart Required after hostname change and again below script needs to continue after restart"

      $cred = New-Object System.Management.Automation.PsCredential("My Domain ID", (ConvertTo-SecureString "My Domain Password" -AsPlainText -Force))
      Add-Computer -DomainName "Mydomain.com" -Credential $cred

    My requirement is : once hostname got changed and it will ask for restart, so machine starts restart, Here after restarting has been finished, the remaining script needs to start automatically which will join the machine in domain.

    Thanks in Advance.!!

    • Moved by Bill_Stewart Friday, March 9, 2018 7:22 PM This is not "scripts on demand"
    Wednesday, August 9, 2017 7:59 AM

All replies

  • Only way I can think of doing it is to split them into two scripts and have the first one change the name and then create a scheduled task to start the other script once the computer has rebooted.

    Hopefully someone offers a better solution :)

    Wednesday, August 9, 2017 8:54 AM
  • Thanks for reply,

    the thing is im deploying this scipts through .xml answer files through WDS.

    So in firstLogon this hostname and domain join needs to be done.

    Any alternate option guys ??

    Wednesday, August 9, 2017 8:58 AM
  • Have a look at this as it may point you in the right direction by using powershell and workflows


    • Proposed as answer by I.T Delinquent Thursday, August 10, 2017 3:05 PM
    Wednesday, August 9, 2017 9:02 AM