简体   繁体   English

使用PowerShell的Start-Process cmdlet传递变量参数

[英]Passing variable arguments using PowerShell's Start-Process cmdlet

Good evening everyone, 各位晚上好,

I'm using a command line that passes arguments to as variables in the following scripts to be run in another ps1 that I'm calling from within this script. 我正在使用一个命令行,该命令行在以下脚本中将参数作为变量传递给变量,以便在我从该脚本内调用的另一个ps1中运行。 Whenever I try to pass the arguments from the command line I get the following error though 每当我尝试从命令行传递参数时,我都会收到以下错误消息

Start-Process : A positional parameter cannot be found that accepts argument Start-Process:找不到接受参数的位置参数

Would anyone be able to assist? 有人可以协助吗?
Thank you for your time and much appreciate any help. 感谢您的宝贵时间,非常感谢您的帮助。

param
(
    [string]$targetserver = $args[0], #target server
    [string]$module = $args[1], #module name
)

function Get-Script-Directory
{    
  return Split-Path $script:MyInvocation.MyCommand.Path
}

Start-Process powershell.exe (Join-Path (Get-Script-Directory) "...\StopServices.ps1") -ArgumentList $targetserver $module

Try this for the last line 尝试此作为最后一行

$scriptPath = Join-Path (Get-Script-Directory) "...\StopServices.ps1"
Start-Process powershell.exe -ArgumentList "-file $scriptPath", $targetserver, $module  

Update due to comment: To show you that it is working see the GIF below - so you may check it again or insert some debug output to see where things go wrong with your script 由于评论而更新:要向您显示它正在运行,请参见下面的GIF-因此您可以再次检查它或插入一些调试输出以查看脚本出了什么问题

GIF显示工作解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM