Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用启动进程调用其他powershell文件时出现问题_Powershell_Batch File - Fatal编程技术网

使用启动进程调用其他powershell文件时出现问题

使用启动进程调用其他powershell文件时出现问题,powershell,batch-file,Powershell,Batch File,编辑:::查看最底部以了解问题的当前状态 在当前设置中,批处理文件使用以下命令调用powershell脚本 powershell D:\path\powershellScript.v32.ps1 arg1 arg2 arg3 arg4 No application is associated with the specified file for this operation $username = "DOMAIN\username" $passwordPlainText = "passwo

编辑:::查看最底部以了解问题的当前状态

在当前设置中,批处理文件使用以下命令调用powershell脚本

powershell D:\path\powershellScript.v32.ps1 arg1 arg2 arg3 arg4
No application is associated with the specified file for this operation
$username = "DOMAIN\username"
$passwordPlainText = "password"     
$password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password

$powershellArguments = "D:\path\deploy.code.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred  -ArgumentList $powershellArguments
我想将其转换为调用另一个powershell的powershell脚本。但是,我在使用启动过程时遇到问题。这是我目前拥有的,但在执行后,我得到以下信息

powershell D:\path\powershellScript.v32.ps1 arg1 arg2 arg3 arg4
No application is associated with the specified file for this operation
$username = "DOMAIN\username"
$passwordPlainText = "password"     
$password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password

$powershellArguments = "D:\path\deploy.code.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred  -ArgumentList $powershellArguments
这是正在执行的powershell

$powershellDeployment = "D:\path\powershellScript.v32.ps1"
$powershellArguments = "arg1 arg2 arg3 arg4"
Start-Process $powershellDeployment -ArgumentList $powershellArguements -verb runas -Wait
编辑:

由于下面的帮助,我现在有以下内容

powershell D:\path\powershellScript.v32.ps1 arg1 arg2 arg3 arg4
No application is associated with the specified file for this operation
$username = "DOMAIN\username"
$passwordPlainText = "password"     
$password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password

$powershellArguments = "D:\path\deploy.code.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred  -ArgumentList $powershellArguments
但是,当我从远程计算机执行此脚本时,会出现“访问被拒绝”错误,即使使用的用户名具有对该计算机的完全管理员访问权限

请更改以下内容:

$powershellArguments = "arg1 arg2 arg3 arg4"


-ArgumentList
参数需要一个参数数组,而不是包含所有参数的单个字符串。

您应该使用
启动进程powershell.exe
,并将脚本路径作为参数列表中的
-File
参数传递。
No application…
位表示您的计算机上没有用于处理.ps1文件的默认应用程序集。如果您在任何.ps1文件上执行整个
右键单击->打开->选择应用程序->选中“将此程序用作默认…”
提示,则消息将消失。我的默认程序是记事本,所以当我在.ps1上使用
Start Process
时,它会在其中弹出

编辑:

总而言之

Start-Process powershell.exe -ArgumentList "-file C:\MyScript.ps1", "Arg1", "Arg2"
或者,如果您像Keith所说的那样定义
$powershellArguments
$powershellArguments=“-C:\MyScript.ps1”、“arg1”、“arg2”、“arg3”、“arg4”
),则如下所示:

Start-Process powershell.exe -ArgumentList $powershellArguments

进行了更改,但是我仍然收到相同的错误
没有应用程序与此操作的指定文件相关联
编辑:我通过删除
$powershellDeployment
周围的引号使其工作,但是特定脚本手动请求参数,这意味着参数更改不起作用。我通过删除
$powershellDeployment
内容周围的引号,使
无应用程序…
消失。到目前为止,脚本按其应该的方式执行,但是它要求参数,这意味着我试图传递的参数没有被传递properly@mhopkins321我已经更新了我的答案,向您展示了完整命令的外观。我用一个脚本测试了这一点,该脚本只回显输入参数,没有问题。你能查看我对上面文章的编辑,看看你是否能帮助解决新问题吗?StackOverflow的格式确实试图限制每个问题一个问题,因此,我建议你用更详细的编辑版本(比如确切的错误消息)来回答一个新问题。但是,我强烈建议您[搜索[()该网站提供了一些其他问题,这些问题可能与您的问题重复,以查看您的问题是否已经得到回答。谢谢!这对我来说也很有效。我刚刚发现,如果您出错,反馈非常糟糕,因此如果可以,您希望一次尝试一个参数。在我的情况下,我正在编写我正在调用的脚本,因此我将RTE输出不需要该脚本的任何参数,然后一次添加一个参数。