我正在构建执行以下操作的脚本
大多数步骤似乎都有效,我只停留在步骤4上。
我使用以下行。
Invoke-Command -FilePath C:\Support\createdomain.ps1 -VMName TEMPLATE-DC
要求提供VM的凭据,然后继续进行操作。直到重新启动。
Restart-Computer -Wait -For PowerShell -Timeout 300 -Delay 2
我也尝试过以下操作,这将重新启动VM,但也会停止Powershell会话,并且不运行启动睡眠
Restart-Computer -Force
Start-Sleep -s 300
所以我的问题是:如何在远程计算机(在本例中为VM)上运行Powershell脚本。并重新启动并等待直到重新启动才能恢复脚本?
这是我得到的错误
The background process reported an error with the following message: "The Hyper-V socket target process has ended.".
+ CategoryInfo : OperationStopped: (TEMPLATE-DC:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
+ PSComputerName : TEMPLATE-DC