问题
在声明if (Test-PendingReboot) { Invoke-Reboot }时,是否有理由在BoxStarter脚本中包括$Boxstarter.RebootOk=$true?
背景
我最近发现了BoxStarter,并注意到有许多脚本包含以下代码:if (Test-PendingReboot) { Invoke-Reboot }。这包括具有以下选项的脚本:$Boxstarter.RebootOk=$true和$Boxstarter.AutoLogin=$true;即那些允许重新启动并根据需要继续运行的脚本。
在BoxStarter站点上做了以下声明:
Boxstarter拦截所有的巧克力安装命令和检查挂起的重新启动。如果检测到挂起的重新启动,Boxstarter将重新启动机器,并自动将用户重新登录并继续安装。
注意:我知道,在进行不更新Invoke-Reboot标志的更改之后,有时可能需要使用PendingReboot;例如,某些注册表更改才能生效;我的问题完全是关于在if (Test-PendingReboot)语句中包装这个命令的使用。
更新:也被问到Google组:https://groups.google.com/forum/#!topic/boxstarter/D0kiRqJyiCY
发布于 2015-03-12 22:56:23
就我个人而言,我永远不会这么做,不。我依赖Boxstarter为我处理这个问题,因为在内部它正在进行相同的检查,因此在我的脚本中这样做是重复的工作。
有时,正如您提到的,您知道由于某种外部原因需要重新启动,所以我会直接调用- reboot,但是这始终会被一个守护子句包围,以防止每次都发生这种情况,因为我总是希望我的脚本是可重复的。
发布于 2016-10-14 22:07:27
我只发现了一个实际需要这样做的情况,正如Gary提到的那样,我用某种逻辑包装它,以避免连续重新启动。
我们遇到的情况是,“新创建的”服务器有一些挂起的文件重命名,即使多次重新启动也不会真正消失,所以如果我们运行Boxstarter,那么如果我们能够在无限重启动之间登录,我们就不得不尽快关闭cmd窗口。
生成的脚本可以通过Install-BoxstarterPackage -DisableReboots <gistUrl>从gist中运行,以清理放入$badFile中的任何文件(您可以列出这些文件)。
对此脚本的一个警告是,它需要登录凭据的交互式提示。如果您信任您的系统和网络,我认为最坏的情况是,您可以使用纯文本密码并组装凭据。
很抱歉,这似乎破坏了语法高亮笔。
Import-Module $env:appdata\Boxstarter\Boxstarter.Common
$badSpoolReg = '\??\C:\Windows\system32\spool\PRTPROCS\x64\1_hpcpp130.dll'
$badSpoolFile = 'C:\Windows\system32\spool\PRTPROCS\x64\1_hpcpp130.dll'
# Next bits taken from the 'Get-PendingReboot' module on the Script Gallery.
$Computer = $env:COMPUTERNAME
$HKLM = [UInt32] "0x80000002"
$WMI_Reg = [WMIClass] "\\$Computer\root\default:StdRegProv"
## Query PendingFileRenameOperations from the registry
$RegSubKeySM = $WMI_Reg.GetMultiStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\","PendingFileRenameOperations")
#$RegSubKeySM # Debug print of the list if you want to run by hand
$RegValuePFRO = $RegSubKeySM.sValue | where { $_ } # Ignore empty values
#$RegValuePFRO # Debug print of the list if you want to run by hand
# Credential is required for Create-BoxstarterTask
# Create-BoxstarterTask required to call Invoke-FromTask
# see https://github.com/mwrock/boxstarter/issues/121
$cred = Get-Credential
Create-BoxstarterTask $cred
# Perhaps could be improved using set membership comparison?
# like (if $badSpoolReg in $RegValuePFRO.Values?)
foreach ($path in $RegValuePFRO) {
if ($path -contains $badSpoolReg) {
write-output "Bogey on my six!"
Get-Service spooler | stop-service
Invoke-FromTask "rm -fo $badSpoolFile" # Files in "protected" paths require extra work to remove
$Boxstarter.RebootOk = $true # Need to enable this to allow Invoke-Reboot to work
Write-output "Took out the bogey, resetting system state"
Invoke-Reboot # Manually called but within a fairly good gate
} else {
write-output "No bogeys sighted Captain!"
}
}
Remove-BoxstarterTaskhttps://stackoverflow.com/questions/29011639
复制相似问题