简体   繁体   English

重新启动后Powershell恢复脚本

[英]Powershell resume script after reboot

I am currently working on a school assignment where i have to make a couple of powershell scripts to perform a basic configuration of a windows server 2012 r2. 我目前正在做学校作业,在这里我必须做几个Powershell脚本来执行Windows Server 2012 R2的基本配置。 First script needs to do the following: 第一个脚本需要执行以下操作:

o Server name: WDC o Ip address: 192.168.1.45 o Subnet: 255.255.255.0 o Gateway: 192.168.1.1 o DNS: 192.168.1.1 o服务器名称:WDC o IP地址:192.168.1.45 o子网:255.255.255.0 o网关:192.168.1.1 o DNS:192.168.1.1
o Administrator password: Admin2016 o Primaire DNS server 8.8.8.8 o Secundaire DNS server 192.168.1.45 o Promote to dc o ... o管理员密码:Admin2016 o Primaire DNS服务器8.8.8.8 o Secundaire DNS服务器192.168.1.45 o升级到DC o ...

Problem is that the server needs to reboot after the name change and that the script cannot continue after this. 问题是名称更改后服务器需要重新启动,并且此后脚本无法继续。

I know I could do this by for example splitting up the script and continuing the second part with runonce in the registry after reboot, but my teacher swears that it is possible to do this in one ps1 file and furthermore he says that it should be possible to autologin after the reboot and then resume the same script file from where it stopped before the reboot. 我知道我可以通过例如重新启动后拆分脚本并在注册表中以runonce继续第二部分的方式来执行此操作,但是我的老师发誓可以在一个ps1文件中执行此操作,而且他说应该可以重新启动后自动登录,然后从重新启动之前停止的位置恢复相同的脚本文件。

This script has to be executed on a local machine, so I can't use workflows. 该脚本必须在本地计算机上执行,因此我无法使用工作流程。 I have been searching for a significant amount of time but can't seem to find any suitable solution to do this exactly how the teacher wants it. 我一直在寻找大量时间,但似乎找不到任何合适的解决方案来完全按照老师的意愿进行。

Hope someone can help. 希望有人能帮忙。

Cheers 干杯

Resuming as such wouldn't be possible. 这样恢复是不可能的。 But you can determine if the changes that need a reboot have already been done and just don't repeat the steps for those settings. 但是您可以确定是否需要重新启动的更改已经完成,而不必重复这些设置的步骤。 Essentially, check if you need to make an adjustment to a step, and only then you need to reboot. 本质上,检查是否需要对步骤进行调整,然后才需要重新启动。 During the second run, your script won't need to re-apply the new settings which need a reboot and should be able to effectively continue where it left off in its previous run. 在第二次运行期间,您的脚本将不需要重新应用需要重新启动的新设置,并且应该能够有效地继续执行上次运行中保留的位置。

As for the auto-login and script re-run parts, both are solvable. 至于自动登录和脚本重新运行部分,都可以解决。 There is a solution using registry settings to auto-logon a user. 有一种使用注册表设置自动登录用户的解决方案。 You'd need to add the password for that login to the registry, so this may be a security concern. 您需要将该登录名的密码添加到注册表,因此这可能是出于安全考虑。 And running a script after logon is possible using the Windows task scheduler. 使用Windows任务计划程序可以在登录后运行脚本。 In addition to using fixed time schedules the scheduler also supports running tasks after certain events. 除了使用固定的时间计划之外,计划程序还支持在某些事件之后运行任务。 There is a delay if you use those events, it can be up to several minutes long. 如果使用这些事件,则会有一段时间的延迟,最长可能长达几分钟。 If that isn't acceptable, you could also use a link to the script in the StartUp folder of the user account used to automatically log on. 如果那是不可接受的,则还可以使用指向用于自动登录的用户帐户的StartUp文件夹中的脚本的链接。

The autologon works with registry keys. 自动登录使用注册表项。 You need a few keys in the HKLM namespace: 您需要在HKLM名称空间中输入一些密钥:

Path: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Value Name: AutoAdminLogon
Value Type: REG_SZ
Value data: 1

Path: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Value Name: DefaultUserName
Value Type: REG_SZ
Value data: <name of the user you want to log on>

Path: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Value Name: DefaultPassword
Value Type: REG_SZ
Value data: <password of the user you want to log on>

and if this is a domain user 如果这是域用户

Path: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Value Name: DefaultDomainName
Value Type: REG_SZ
Value data: <name of the domain the user belongs to>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查是否需要重新启动并在重新启动后继续执行 Powershell 脚本? - Check if a reboot is needed and continue Powershell script after reboot? 使用 PowerShell 直接重启服务器计算机并恢复脚本 - Restart server computer with PowerShell Direct and resume the script 计算机重启后恢复批处理脚本 - Resume batch script after computer restart Powershell Mount Point Automation:重启后会显示驱动器号 - Powershell Mount Point Automation: Drive letter appears after reboot 厨师重新启动资源会导致厨师运行超时,然后Windows服务器才能在更新和恢复配方后启动备份 - Chef reboot resource causes chef run to time out before Windows server is able to start back up after update and resume recipe 重新启动并继续批处理脚本 - Reboot & continue batch script WinPE Windows 10 成像——无法在批处理脚本中的“暂停”后调用“wpeutil 重启” - WinPE Windows 10 Imaging -- Unable to call 'wpeutil reboot' after 'PAUSE' in BATCH script 从脚本打开 Powershell 后将命令传递给管理员 Powershell - Passing command to Admin Powershell after opening Powershell from script 更改PATH后必须重新启动 - Must reboot after changing PATH 重新启动后删除注册表项 - Registry entry is deleted after reboot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM