Afternoon guys,
I'm working on a script that creates an initial Domain Controller. I've been running into an error and I feel like it's related to the creation of the Forest and the server restarting. The error in question is
powershell remoting processing data from remote server failed with the following error message: the I/O operation as been aborted because of either a thread exit or an application request
I have the Forest being created through invoke-command
and the server restarting within that script block and a timer that waits 8 mins and then restarts the server again. The issue I run into is I'm trying to pull the initial restart out of the invoke-command
scriptblock but it's giving me Access Denied permission errors.
The computer is skipped. Fail to retrieve its LastBootUpTime via the WMI service with
the following error message: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
Now if I have the restart within the invoke-command
block so it runs locally on the server, the only error I get is the first one. If I pull it out I get the second error, which I know the credentials are correct as it's the same credentials I use when running invoke-command
(The account in question is the built-in administrator for the initial build-out).
Below is a block of my code, I guess my real question is, what would be causing my first error with the remote operation failing
Invoke-Command -ComputerName $IP -Credential $AdminCred -ScriptBlock {
Write-Output "Promoting to Primary Domain Controller... "
Install-ADDSForest -DomainName $using:Domain -InstallDNS -NoRebootOnCompletion -Force -SkipPreChecks -SafeModeAdministratorPassword $Using:DomainAdminPass -WarningAction SilentlyContinue
Restart-Computer -Force
}
#What I've also tried but gives the Access Denied error
#Restart-Computer -ComputerName $IP -Credential $AdminCred -Wait -For PowerShell -Force
# Creates a Progress Bar Timer, set for 6 minutes, to wait for the server to reboot.
Write-Log "Restarting $HostName... " -NoNewLine
For($i=0; $i -le 360; $i++){
Write-Progress -Activity "Performing Initial Configuration. This will take approx. 8 minutes" -Status "Working..." -SecondsRemaining (480 - $i)
Sleep -s 1
}
Write-Progress -Activity "Performing Initial Configuration. This will take approx. 8 minutes" -Completed
#Performs another remote reboot of the DC to confirm it has rebooted
#DOES NOT GIVE an Access denied error, if the DC was restarted locally through invoke-command
Restart-Computer -ComputerName $IP -Credential $AdminCred -Wait -For PowerShell
#Pauses the script for 45 seconds to allow the DC to fully initialize
For($i=0; $i -le 60; $i++){
Write-Progress -Activity "Finalizing Initial Configuration" -Status "Finalizing..." -SecondsRemaining (60 - $i)
Sleep -s 1
}
Write-Progress -Activity "Finalizing Initial Configuration" -Completed