Not able to open or execute PowerShell script using notepad or PS ISE, PS ISE as and Admin?

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
akanoongo
Posts: 6
Last visit: Tue Jun 15, 2021 10:04 pm

Not able to open or execute PowerShell script using notepad or PS ISE, PS ISE as and Admin?

Post by akanoongo »

Hello

I am not able to open any PowerShell script using notepad or PS ISE or PS ISE or PrimalScript IDE as and Admin from D Drive. I am not able to any of the PowerShell script. I am using Windows 10 and PS Version is 5.0.

I am getting following errors
- Unable to load "d:\ps\userscript.ps1". Access to "d:\ps\userscript.ps1" is denied.

Something wrong only with PowerShell scripts. I can open all other type of files.

When I checked Get-ExecutionPolicy –List, getting following output

MachinePolicy Restricted
UserPolicy Undefined
Process Undefined
CurrentUser Bypass
LocalMachine RemoteSigned


Looks like problem with MachinePolicy. Then I tried

Set-ExecutionPolicy -Scope MachinePolicy Unrestricted

but getting following error

Set-ExecutionPolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must be set through Group Policy.
At line:1 char:1
+ Set-ExecutionPolicy -Scope MachinePolicy Unrestricted
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-ExecutionPolicy], InvalidOperationException
+ FullyQualifiedErrorId : CantSetGroupPolicy,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand


Please let me know what I am missing here.

AK
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Not able to open or execute PowerShell script using notepad or PS ISE, PS ISE as and Admin?

Post by jvierra »

"Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must be set through Group Policy."

This is a pretty obvious message.

To set the global policy you must be an admin running elevated.

Set-ExecutionPolicy RemoteSigned[\b]

"- Unable to load "d:\ps\userscript.ps1". Access to "d:\ps\userscript.ps1" is denied."

This means that you do not have access permission on the file or folder. It has nothing to do with execution policy.
User avatar
akanoongo
Posts: 6
Last visit: Tue Jun 15, 2021 10:04 pm

Re: Not able to open or execute PowerShell script using notepad or PS ISE, PS ISE as and Admin?

Post by akanoongo »

jvierra

I understand and agree with your point.

I am wondering how it is suddenly stopped working when I am working from some different country, earlier I was working from my company office that time I was not facing issue.

I can not do any development work, Is there any way to fix it?

AK
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Not able to open or execute PowerShell script using notepad or PS ISE, PS ISE as and Admin?

Post by jvierra »

Fix what? There is no way for us to know what your system issue is. The errors are clear. You need permission on the file which you don't have. What does that have to do with a country?
User avatar
akanoongo
Posts: 6
Last visit: Tue Jun 15, 2021 10:04 pm

Re: Not able to open or execute PowerShell script using notepad or PS ISE, PS ISE as and Admin?

Post by akanoongo »

As per my understanding it is look like group policy issue. However I already did gpupdate /force.

However If I logged in with different account I am able to access script without any issue. for the time being it is ok for me.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked