title: ADDSForrest installation script won't reboot after completion
body: <p>Before you try to respond to the title</p>
  
  <p><strong>I am using the -force and the -confirm:$false arguments.</strong> </p>
  
  <p>I have been tasked with writing a script that will completely automate the promotion of a server to a new active directory forest, however, my program hangs once it's done actually promoting the server from the <code>Install-ADDSForest</code> command. It completes the domain controller operation but fails to return execution back to the script, and it fails to automatically restart the computer. I have tried both using the automatic restart from the command, and suppressing the automatic restart and doing a manual restart, but no dice: control never returns from the command.</p>
  
  <p>When I run it as a job, the only manual way to force it to continue is to close the window the task is resident to, open another powershell window and resume the job. The computer immediately restarts as it should. I could script this process of closing the original window and continueing from somewhere else, but this seems like an awful hack. I'm the only person with a software development background, everyone else is IT, so I'm not sure I could explain why I need to do this in documentation, and it would make maintaining the code that much more difficult.</p>
  
  <p><strong>I am using powershell workflow. The problem does not exist outside of powershell workflow but I need workflow to run the script with checkpoints so I can continue after I restart. I could do this with multiple files, and variables to track progress, but that would render my code almost non-extensible.</strong></p>
  
  <p>Relevent log entries below (including the point where I get fed up and use my workaround to reboot after leaving my program overnight) </p>
  
  <pre><code>07/05/2017 16:31:22 [INFO] DsRolepSetDCLocatorPostPromoState: got 0 creating the DSROLEP_DCLOCATOR_PREREBOOT_HINT key
  07/05/2017 16:31:22 [INFO] The attempted domain controller operation has completed
  07/05/2017 16:31:22 [INFO] Updating service status to 4
  07/05/2017 16:31:22 [INFO] DsRolepSetOperationDone returned 0
  07/05/2017 19:30:35 [INFO] Updating service status to 3
  07/05/2017 19:30:35 [INFO] DS Role Server Service shutting down
  07/05/2017 16:31:22 [INFO] DsRolepSetDCLocatorPostPromoState: got 0 creating the DSROLEP_DCLOCATOR_PREREBOOT_HINT key
  07/05/2017 16:31:22 [INFO] The attempted domain controller operation has completed
  07/05/2017 16:31:22 [INFO] Updating service status to 4
  07/05/2017 16:31:22 [INFO] DsRolepSetOperationDone returned 0
  07/05/2017 19:30:35 [INFO] Updating service status to 3
  07/05/2017 19:30:35 [INFO] DS Role Server Service shutting down
  </code></pre>
  
  <p>Minimal code example documenting my problems below:</p>
  
  <pre><code>#requires -runasadministrator
  param(
  [parameter(mandatory=$true)]
  [string]
  $rootDomainName,
  [parameter(mandatory=$true)]
  [string]
  $netBiosName
  )
  
  
  
  workflow New-adsetup{
  param(
  [parameter(mandatory=$true)]
  [string]
  $rootDomainName,
  [parameter(mandatory=$true)]
  [string]
  $netBiosName
  )
  
  
  function promoteandinstall{ 
  param(
  [parameter(mandatory=$true)]
  [string]
  $rootDomainName,
  [parameter(mandatory=$true)]
  [string]
  $netBiosName
  )
  
  echo "!!!begin promote to AD!!!"
  
  echo "!installing windows feature!"
  
  Install-WindowsFeature -name AD-Domain-Services  
  
  echo "!feature installed!"
  
  
  
  Import-Module ADDSDeployment
  Install-ADDSForest `
  -Force:$true `
  -confirm:$false `
  -skipPrechecks:$true `
  -DomainMode "Win2012R2" `
  -DomainName $rootdomainname `
  -DomainNetbiosName $netbiosname `
  -ForestMode "Win2012R2" `
  -InstallDns:$false `
  -NoRebootOnCompletion:$true &lt;#$true#&gt; `
  -SafeModeAdministratorPassword (convertto-securestring "P4ssw0rd" -asplaintext -force) 
  
  restart-computer -force
  }
  
  promoteandinstall -rootDomainName $rootDomainName  -netBiosName $netBiosName
  
  md D:\ThisCommandRunAfterReboot
   }
  
  
   $AtStartup = New-JobTrigger -AtStartup
   Register-ScheduledJob -Name ADSetup -Trigger $AtStartup -ScriptBlock `
    {Import-Module PSWorkflow;
     Get-Job ADSetup -State Suspended | Resume-Job}
  
  
   New-ADSetup -rootDomainName $rootDomainName -PSPersist:$true `
   -netBiosName $netBiosName  -AsJob -JobName ADSetup
  
  
   Unregister-ScheduledJob -Name ADSetup
  </code></pre>