Scripting >> Powershell >> How to ensure that script files with .ps1 extension can be executed by powershell

 

## Ensure .ps1 file association is defined
## from command prompt open as administrator

assoc .ps1=Microsoft.PowerShellScript.1

ftype Microsoft.PowerShellScript.1=%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -File "%1"



## Verify by looking at the (Default) value for following registry key

HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command


## If it is still showing notepad.exe or something other than powershell.exe, change it from windows explorer
## Example for Windows 11


## Verify the registry again





## launch powershell as administrator and set the ExecutionPolicy to either RemoteSigned or UnRestricted
## so that local scripts can run

set-executionpolicy -ExecutionPolicy RemoteSigned

or

set-executionpolicy -ExecutionPolicy UnRestricted