1

How can I get my PowerShell script to execute?

When I run my script I get the error:
File cannot be loaded because the execution of scripts is disabled on this system

Can you help me to get my script to run?

set-executionpolicy unrestricted
#Set-ExecutionPolicy RemoteSigned

$target=[IO.File]::ReadAllText(".\usermenuTest1.4d")
$output=[IO.File]::ReadAllText(".\usermenuTest2.4d")

($output -replace $target) | Set-Content "usermenuTest2.4d.new"

Start-Sleep -s 10
1
  • You can always disable/enable the UAC prompt at the beginning of the script and renable it at the end. Via Set-ItemProperty -Path REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name ConsentPromptBehaviorAdmin -Value 0 This way you don't enable or disable script execution globally on the machine. See.stackoverflow.com/questions/79230965/… Commented Dec 1, 2024 at 18:13

1 Answer 1

3

This Technet article suggests trying Get-ExecutionPolicy to check your script execution policy, and then set it to AllSigned or Unrestricted. Also, make sure you run the script like this ".\scriptname.ps1"

Sign up to request clarification or add additional context in comments.

3 Comments

RemoteSigned is another widely used value for ExecutionPolicy.
& powershell.exe -executionpolicy bypass -file C:\script.ps1 to completely ignore the execution policy.
You can also use Set-ExecutionPolicy Unrestricted -Scope Process -Force to temporarily get around it without changing system defaults

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.