I note the format of the script during no longer exists (39:56) remotes to the DC. As we do not have remote PS rights to our DCs, I can't figure out how else to make this work.
The error we get when we try using $env:COMPUTERNAME in place of the $DC variable is:
Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running.
Of course, I have installed AD Web Services on this machine and it works perfectly well using PowerShell ISE.
The original runbook had encrypted credentials and remoted to another server using credssp, but using certs to encrypt our credentials is a bit of a pain.
How can I get this script to work in CPA?