Execution Policy Issue - ExecutionPolicy -bypass not working

Welcome Forums General PowerShell Q&A Execution Policy Issue - ExecutionPolicy -bypass not working

This topic contains 1 reply, has 1 voice, and was last updated by

 
Participant
9 months, 1 week ago.

  • Author
    Posts
  • #93489

    Participant
    Points: 18
    Rank: Member

    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."

  • #93492

    Participant
    Points: 18
    Rank: Member

    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...

The topic ‘Execution Policy Issue - ExecutionPolicy -bypass not working’ is closed to new replies.