Why does pwsh think I'm not in an administrator shell when I provide LocalMachine, but not CurrentUser, as the -Scope of Set-ExecutionPolicy?
#25729
-
ContextI'm attempting to unrestrict the execution policy: 1 #!/usr/bin/env pwsh
#Requires -PSEdition Core
#Requires -Version 7.6.0
#Requires -RunAsAdministrator
If ($IsWindows) { Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Unrestricted -Force }...for microsoft/WSL#13224 (comment): #!/usr/bin/env pwsh
#Requires -PSEdition Core
#Requires -Version 7.6.0
#Requires -RunAsAdministrator
& "$Env:UserProfile\Downloads\collect-wsl-logs.ps1"...which fails, since it's somehow restricted itself since I last ran that script:
Attempted Elevation Methods
Environment
Footnotes |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
|
Somehow, #!/usr/bin/env pwsh
#Requires -PSEdition Core
#Requires -Version 7.6.0
#Requires -RunAsAdministrator
- Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Unrestricted -Force
+ Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force...works:
However, this doesn't explain the error, so I shan't close the thread. |
Beta Was this translation helpful? Give feedback.
-
|
You're trying to set the execution policy for local machine, so I would suggest two things:
|
Beta Was this translation helpful? Give feedback.



Msix/store apps are installed and protected with an ACE that only
NT SERVICE\TrustedInstallerhas access to. Technically as an admin you can change the owners or add yourself/any user with write access but that needs to be explicitly done before you can modify the files/directory.See https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.5#known-limitations for known limitations around this.