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

Ask your Windows 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.
Locked
User avatar
akanoongo
Posts: 6
Joined: Mon Mar 12, 2018 7:02 am

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

Post by akanoongo » Wed Apr 24, 2019 3:11 am

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: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Apr 24, 2019 5:21 am

"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
Joined: Mon Mar 12, 2018 7:02 am

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

Post by akanoongo » Wed Apr 24, 2019 5:57 am

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: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Apr 24, 2019 6:14 am

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
Joined: Mon Mar 12, 2018 7:02 am

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

Post by akanoongo » Wed Apr 24, 2019 8:11 am

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.

Locked