ADDSForrest安装脚本在完成后不会重新启动

时间:2017-07-06 19:07:52

标签: windows powershell active-directory powershell-v4.0 powershell-workflow

在您尝试回复标题之前

我正在使用-force和-confirm:$ false参数。

我的任务是编写一个脚本,它可以完全自动地将服务器升级到新的活动目录林,但是,一旦它从Install-ADDSForest命令实际升级服务器,我的程序就会挂起。它完成域控制器操作但无法将执行返回到脚本,并且无法自动重新启动计算机。我已尝试使用命令中的自动重启,并禁止自动重启和手动重启,但没有骰子:控制永远不会从命令返回。

当我将其作为作业运行时,强制它继续运行的唯一手动方法是关闭任务驻留的窗口,打开另一个PowerShell窗口并恢复作业。计算机立即重新启动。我可以编写关闭原始窗口并从其他地方继续的过程,但这看起来像是一个糟糕的黑客。我是唯一一个拥有软件开发背景的人,其他人都是IT,所以我不确定我能解释为什么我需要在文档中执行此操作,这会使代码维护起来更加困难。

我正在使用PowerShell工作流程。这个问题在powershell工作流程之外不存在,但是我需要工作流来运行带有检查点的脚本,所以我可以在重新启动后继续。我可以使用多个文件和变量来跟踪进度,但这会使我的代码几乎不可扩展。

下面的相关日志条目(包括让我厌倦的地方,并在我的程序过夜后使用我的解决方法重启)

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

记录下面我的问题的最小代码示例:

#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 <#$true#> `
-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

0 个答案:

没有答案