PowerShell scripts that require a connection to Active Directory may fail when executed through Advanced Actions.
This occurs because scripts configured in Advanced Actions are run while the restore process is still in the DSRM phase.
In DSRM, Active Directory services are not fully available, which prevents scripts from establishing a successful connection.
In this scenario, scripts that require a connection to Active Directory do not work correctly when executed through Advanced Actions, as AD is not yet available during the DSRM phase. Scripts in this stage are intended for tasks such as adjusting the contents of SYSVOL, removing potentially harmful objects, or performing actions that must occur while the system is in DSRM.
As an alternative, ConsoleSideScripting.wsf can be used, which allows scripts to run at different stages of the restore process, including after the forest restore is complete and Active Directory is fully available.
While ConsoleSideScripting.wsf uses VBScript or JScript, you can create a simple wrapper script to call and execute a PowerShell script.
Example:
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "powershell.exe -ExecutionPolicy Bypass -File C:\Scripts\Test.ps1", 0, True
For more details about ConsoleSideScripting.wsf, please refer to the documentation in the link below.