Author Posts

February 12, 2018 at 4:01 pm

I have a batch file that is calling a PowerShell script. The PowerShell script performs various tasks before and after adding a computer to the domain. After the machine is added to the domain, Group Policy sets the execution policy to "RemoteSigned." I have not had an issue using the "ExecutionPolicy -bypass" switch when opening a PowerShell script in the past. Why does PowerShell think the script is a remote script after adding the machine to the domain? Is there something I need to change or add to the batch file?

PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -NoExit -ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"

Edit: I forgot to add that when running the script, I receive the error:
" File C:... cannot be loaded. The file "FILE.ps1" is not digitally signed. You cannot run this script on the current system."

February 12, 2018 at 4:24 pm

Ah – Turns out the user that was getting this error copied the script to their home drive and THEN to a USB drive, which blocked the file. I think Unblock-File works in this instance, but don't think this will be an issue in the future since the file won't be copied that way...