2

I wanted to use yeoman to create an add-in for the office with angular. After installing requirement tools like nodeJs, angular, yeoman, generator-office in power shell, I have tried to run this code

yo office 

But I have been got this error:

 yo : File C:\Users\ME\AppData\Roaming\npm\yo.ps1 cannot be loaded. 
The file C:\Users\ME\AppData\Roaming\npm\yo.ps1 is not digitally signed. 
You cannot run this script on the current system. 
For more information about running scripts and setting execution policy, 
see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ yo office
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess  
  • The following is general information based on the _default_ configuration; your effective execution policy appears to be `AllSigned`; for details, see the linked duplicate or [this answer](https://stackoverflow.com/a/67827931/45375). – mklement0 Oct 15 '21 at 22:44
  • On Windows workstations, PowerShell script execution is disabled by default. Enable it with [`Set-ExecutionPolicy`](https://docs.microsoft.com/powershell/module/microsoft.powershell.security/set-executionpolicy).`-Scope` accepts one of 3 scopes; more specific ones have higher precedence: `LocalMachine` (requires admin rights), `CurrentUser`, or `Process` (current process only). The PowerShell CLI accepts a process-specific `-ExecutionPolicy ` too . Execution policies can also be set via GPO, in which case they cannot be changed or overridden via `Set-ExecutionPolicy` or the CLI. – mklement0 Oct 15 '21 at 22:44

1 Answers1

4

After I have read about this error in this link here, I find that I should change the execution policy of "currentUser".

  1. run this code to see your system's execution policies in PowerShell.
Get-ExecutionPolicy -List
  1. If your CurrentUser ExecutionPolicy is "undefined", you should change it to "RemoteSigned" with this code
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

I have tested it in windows 10 pro x64, Yeoman 4.3.0, NodeJs 14.17.0, NPM 6.14.13

mklement0
  • 382,024
  • 64
  • 607
  • 775