Working with scripts in powershell – TypeScript Compiler (tsc) problem – Fix

Problem

PS D:\TypeScriptWorkspace> tsc

tsc : File C:\Users\islenmisveri\AppData\Roaming\npm\tsc.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http

s:/go.microsoft.com/fwlink/?LinkID=135170.

At line:1 char:1

+ tsc

+ ~~~

    + CategoryInfo          : SecurityError: (:) [], PSSecurityException

TL;DR

PS D:\TypeScriptWorkspace> get-executionpolicy

PS D:\TypeScriptWorkspace> Set-ExecutionPolicy -Scop CurrentUser

ExecutionPolicy: RemoteSigned

Control

PS D:\TypeScriptWorkspace> get-executionpolicy

Restricted

Below is the list of four different execution policies in PowerShell

  • Restricted – No scripts can be run.
  • AllSigned – Only scripts signed by a trusted publisher can be run.
  • RemoteSigned – Downloaded scripts must be signed by a trusted publisher.
  • Unrestricted – All Windows PowerShell scripts can be run.

PS D:\TypeScriptWorkspace> Set-ExecutionPolicy -Scop CurrentUser

cmdlet Set-ExecutionPolicy at command pipeline position 1

Supply values for the following parameters:

ExecutionPolicy: RemoteSigned

Result;

PS D:\Workspace> tsc

Version 4.1.3

Syntax:   tsc [options] [file…]

Examples: tsc hello.ts

          tsc –outFile file.js file.ts

          tsc @args.txt

          tsc –build tsconfig.json

Options:

 -h, –help                                         Print this message.

 -w, –watch                                        Watch input files.

 –pretty                                           Stylize errors and messages using color and context (experimental).

 –all                                              Show all compiler options.

 -v, –version                                      Print the compiler’s version.

quotation;

powershell -ExecutionPolicy ByPass -File script.ps1
(https://tecadmin.net/powershell-running-scripts-is-disabled-system/)

Yorum bırakın