首页 > 解决方案 > 从节点 js 执行 Powershell 脚本失败

问题描述

我有一个我们为系统管理开发的 Powershell 脚本列表。这些脚本是使用“child_process”模块从 Node JS 应用程序调用/执行的。在我的笔记本电脑上一切正常。将 Node JS 应用程序传输到 Centos7 服务器后,我收到如下错误:

The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

我检查了 Powershell 执行策略 - 一切都设置为Unrestricted. 以用户身份 ssh 到服务器后,我可以从命令行执行相同的脚本而不会出现任何错误root。我看到的唯一区别是 Node JS 应用程序正在使用不同的用户运行。

标签: node.jspowershell

解决方案


发现问题 - 所有模块都安装在/root/.local/share/powershell/Modules目录下,并且在运行 Node JS 应用程序的用户配置文件下没有安装任何内容。复制了应用用户目录下的所有模块,/home/ndjs/.local/share/powershell/Modules/现在一切正常。


推荐阅读