SecurityError: (:) [], PSSecurityException UnauthorizedAccess Powershell

Total
0
Shares

As soon as I open Visual Studio Code, the following appears in VSCode’s own console:

Cannot load file C:\Users\admin\Documents\WindowsPowerShell\profile.ps1
because script execution is disabled on this system. to get more
information, see the about_Execution_Policies topic on
https:/go.microsoft.com/fwlink/?LinkID=135170.
Online: 1 Character: 3
+ . 'C:\Users\admin\Documents\WindowsPowerShell\profile.ps1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
    + CategoryInfo : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
Loading the personal and system profiles took 643ms.

I don’t know if it has anything to do with it or not, but a few hours before I had installed node, npm and typescript (although I really updated them, since I had them from before).

The subject and my urgency in this problem is that I am doing a JavaScript course where TypeScript is used in a section. So, that was the reason why I got to update those “tools”.

In addition, given a moment of the course I have to execute the following script:

tsc clase148.ts

I get the following error:

tsc : Cannot load file C:\Users\admin\AppData\Roaming\npm\tsc.ps1 because the
script execution is disabled on this system. For more information,
see the about_Execution_Policies topic on
https:/go.microsoft.com/fwlink/?LinkID=135170.
Online: 1 Character: 1
+ tsc class148.ts
+ ~~~
    + CategoryInfo : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Solution 1

You must run the powershell as administrator and execute the command Set-ExecutionPolicy Unrestricted.

or run this –

Set-ExecutionPolicy -Scope CurrentUser unrestricted

Solution 2

  1. Run windows + R –> gpedit.msc
  2. go to Administrative Templates > Windows Components > Windows PowerShell >
  3. Select Enable script execution, right click, edit
  4. Select Enabled and Allow all scripts, Apply

Conclusion

The powershell in visual studio code throws error “Unauthorized access SecurityError: (:) [], PSSecurityException” can be resolved by executing Set-ExecutionPolicy Unrestricted command. The poweshell needs to be opened in administrative mode.

Leave a Reply

Your email address will not be published. Required fields are marked *