I have a PowerShell script which I used to add machine to a domain. The purpose is to allow me to snap a VM to a clean state, before machine has been added to a domain.
I would like to be able to setup the snapshot of the VM so that when it starts up, it automatically runs the PowerShell script.
I tried populating the following registry key, but this only works after user logs on.
I then tried the following registry key, but nothing seems to happen:
I also tried creating a scheduled task to call the script, and configured the task to run on start up, but nothing happen.
I think with the last two approach, the script is getting called too early, before a required service is loaded.
I know the script works, because it works when I call it on command line, and it works when I use the log on method (RunOnce) registry key.
Here's the PowerShell script:
$domainAcc=$domainName + "\MyAdminUserName"
$comp = get-wmiobject Win32_ComputerSystem
$reboot = (gwmi -Class Win32_OperatingSystem)
$reboot.psbase.scope.options.enableprivileges = $true
Here's the DOS script which is used to call the PowerShell script:
rem schtasks /Delete /TN AddMachineToTestlabDomain
rem Above is only needed when using task schedule method
powershell Set-ExecutionPolicy RemoteSigned
Does anyone know how I can configure Windows 2008 machine to automatically get added to a domain on bootup without requiring user to log on?
Or how to call above script on bootup without requiring user to log on?