- Newest
- Most votes
- Most comments
Have you tried using the start-job and wait-job powershell commands for the install.ps1 script? This may provide the time this scripts needs to complete.
Hope this helps, if it does please accept this answer.
If using SSM aka AWS Systems Manager, then save yourself the trouble and use the free built in AWS automation document called AWSSupport-UpgradeWindowsAWSDrivers [1]
This automation document has all the checks and balances in place and achieves your objective.
Now if you still want to DIY this with your own script then consider using exit code 3010 in place of Restart-Computer
"For Windows managed nodes, you specify exit 3010 in your script. For Linux and macOS managed nodes, you specify exit 194. The exit code instructs AWS Systems Manager Agent (SSM Agent) to reboot the managed node, and then restart the script after the reboot completed. Before starting the reboot, SSM Agent informs the Systems Manager service in the cloud that communication will be disrupted during the server reboot."
"When developing scripts that reboot managed nodes, make the scripts idempotent so the script execution continues where it left off after the reboot. Idempotent scripts manage state and validate if the action was performed or not. This prevents a step from running multiple times when it's only intended to run once." [2]
Example of idempotent code:
If (desired package not installed) { Install package exit 3010 }
References:
[2] https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-reboot.html
Relevant content
- asked 2 months ago
- asked 4 months ago
- asked 7 months ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 7 months ago