Let’s assume your script needs to change a bunch of system settings. The worst thing that could happen is if your script breaks in the middle of changing things, leaving you with only parts of changes.
Provided system restore points are enabled on your machine and your script has admin privileges, PowerShell can easily create restore points and restore the system if anything went bad. Note though some of the limitations: Restore points only work past Windows XP. They only work for clients, not servers. And you can only create one restore point every 24hrs.
This is how you create a restore point:
PS> Checkpoint-Computer -Description 'Before script execution'
Get-ComputerRestorePoint returns all the restore points available on your system. You could filter out your new restore point like this:
PS> Get-ComputerRestorePoint | Where-Object { $_.Description -eq 'Before script execution' }
To restore the computer and revert changes made since, you need the sequence number of the restore point to use. Then, submit this number to Restore-Computer.
PS> $id = Get-ComputerRestorePoint | Where-Object { $_.Description -eq 'Before script execution' } | Select-Object -ExpandProperty SequenceNumber PS> Restore-Computer $id -WhatIf