NodeJS - 子进程 - Exec VS Powershell ISE |为什么结果不同?为什么无法创建 PSCredential?

问题描述 投票:0回答:1

我的 PS 脚本:

$admin = "TEST"
$Password =  ConvertTo-SecureString "Test12345" -AsPlainText -Force
$Credential = [PSCredential]::new( $admin, $Password)
if ($Credential -is [System.Management.Automation.PSCredential]) {
return "PS Credentials - true"
} else {
return "PS Credentials - false"
}

PS ISE 结果: enter image description here

我的 NODE JS 脚本:

"use strict";
const { exec } = require("child_process");

exec(
    "powershell.exe -File C:\\Users\\fschiller\\Desktop\\Projekt_Node\\Libary\\TEST.ps1",
    (error, stdout, stderr) => {
      console.log(stdout)
    }
)

节点脚本中 VSCode 的结果: enter image description here

我不知道如何解决它。有人可以帮忙吗?或者知道问题所在以及如何解决它?

尝试过ExecFile, 创建 PSCredential 对象的其他方法, "terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "绕过"]

javascript node.js powershell visual-studio-code child-process
1个回答
0
投票

如果我将模块指定为完整路径 - Import-Module -Name “C:\Windows\System32\WindowsPowerShell 1.0\Modules\Microsoft.PowerShell.Security\Microsoft.PowerShell.Security.psd1”,它就可以工作

© www.soinside.com 2019 - 2024. All rights reserved.