脚本中间重启机器并继续脚本。 [英] Mid of the script restart the machine and continue the script.

查看:106
本文介绍了脚本中间重启机器并继续脚本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面提到的主机名更改脚本&域自动加入。

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")

    $ ComputerName.rename(" $ name")

    重新启动 - 计算机



    " 重新启动主机名更改后需要重新启动脚本需要在重新启动后继续"
    $




    $ 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.

先谢谢。!!

推荐答案

我能想到的唯一方法是将它们分成两个脚本并让第一个更改名称,然后创建一个计划任务,以便在计算机重新启动后启动另一个脚本。

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 :)


这篇关于脚本中间重启机器并继续脚本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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