如果脚本运行True,则重新启动/运行下一部分 [英] if script runs true restart/run next part

查看:25
本文介绍了如果脚本运行True,则重新启动/运行下一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让脚本在脚本返回$TRUE时重新启动计算机,我计划在SCCM或任务调度程序中运行该脚本。 如果返回$True,我打算让SCCM重新启动计算机,但不知道如何操作,所以现在我正尝试在脚本本身中添加重新启动,但不知道如何正确添加它。

function Test-PendingReboot
{
 if (Get-ChildItem "HKLM:SoftwareMicrosoftWindowsCurrentVersionComponent Based ServicingRebootPending" -EA Ignore) { return $true }
 if (Get-Item "HKLM:SOFTWAREMicrosoftWindowsCurrentVersionWindowsUpdateAuto UpdateRebootRequired" -EA Ignore) { return $true }
 if (Get-ItemProperty "HKLM:SYSTEMCurrentControlSetControlSession Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
 try { 
   $util = [wmiclass]"\.
ootccmclientsdk:CCM_ClientUtilities"
   $status = $util.DetermineIfRebootPending()
   if(($status -ne $null) -and $status.RebootPending){
 return $true
   }
 }catch{}

 return $false
}

If $true) {
  Restart-Computer

  }  Else {
  exit 
}  

推荐答案

if(测试-挂起重新启动-eq"True") { 您的重启代码 )

这篇关于如果脚本运行True,则重新启动/运行下一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆