使用启动过程中的问题来调用其它文件的PowerShell [英] Problems using start-process to call other powershell file
问题描述
:::见问题当前状态最底部。
:::See very bottom for current state of issue.
在设置当前,一个批处理文件将调用PowerShell脚本以下</ P>
In the current set up, a batch file calls a powershell script with the following
powershell D:\path\powershellScript.v32.ps1 arg1 arg2 arg3 arg4
我想这个转换为PowerShell脚本调用另一个PowerShell的。然而,我在使用启动过程的问题。这是我目前有但在执行我得到以下
I would like to convert this into a powershell script calling another powershell. However, I'm having issues using start process. This is what I currently have but upon execute I get the following
No application is associated with the specified file for this operation
这是执行的PowerShell
This is the powershell that is executing
$powershellDeployment = "D:\path\powershellScript.v32.ps1"
$powershellArguments = "arg1 arg2 arg3 arg4"
Start-Process $powershellDeployment -ArgumentList $powershellArguements -verb runas -Wait
:::::
由于下面的帮助,我现在有以下
Due to the help below, I now have the following
$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
然而,当我从远程计算机上执行这个脚本,我得到拒绝访问错误,即使使用的用户名具有本机完全管理员访问
However, when I execute this script from a remote machine I get "access denied" errors, even though the username used has full administrator access to the machine
推荐答案
您应该使用开始处理powershell.exe
,并通过脚本路径为在ARG列表 - 文件
参数。在没有应用程序...
位意味着你没有一个默认的应用程序集与你的机器上的.ps1文件工作。如果你做全右键 - &GT;打开方式 - &GT;选择应用程序 - &GT;勾选使用此程序设置为默认......
上的任何文件名为.psl珍闻,则该消息消失。我的默认程序为记事本,所以当我使用开始处理
上名为.ps1,它在弹出它。
You should be using Start-Process powershell.exe
, and passing the path to the script as the -File
argument in your arg list. The No application...
bit means that you don't have a default application set to work with .ps1 files on your machine. If you do the whole Right Click -> Open With -> Select Application -> check "Use this program as default..."
tidbit on any .ps1 file, then the message goes away. My default program is notepad, so when I use Start-Process
on a .ps1, it pops it up in that.
编辑:
要把它放在一起......
To put it all together...
Start-Process powershell.exe -ArgumentList "-file C:\MyScript.ps1", "Arg1", "Arg2"
或者,如果你定义 $ powershellArguments
基思说( $ powershellArguments = - 文件C:\\ MyScript.ps1,ARG1 ARG2,ARG3,ARG4
),那么这样的:
Or, if you define $powershellArguments
as Keith says ($powershellArguments = "-file C:\MyScript.ps1", "arg1", "arg2", "arg3", "arg4"
), then like this:
Start-Process powershell.exe -ArgumentList $powershellArguments
这篇关于使用启动过程中的问题来调用其它文件的PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!