0

I have a powershell script that contains the following

$username = 'username'
$password = 'password'
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
start-process -FilePath $deploymentAppPath -Credential $cred

Yet when I execute this I get the following error.

start-process <<<<  -FilePath $deploymentAppPath -Credential $cred
+ CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

While I don't think it is probably obvious, my end goal here is to call the batch file with the user credentials that I specify.

4

2 回答 2

1

我将从删除安全字符串的使用开始。在我的经验中,有些事情似乎并不适用。

看来您的进程是本地的,因此您没有通过网络传输 u/p。安全字符串真的有必要吗(考虑到 u/p 在脚本中并且对脚本有权限的人都可以使用)?

于 2012-07-23T15:07:31.307 回答
1

我相信您没有正确版本的 windows powershell 来使用该start-process命令。我运行了这个,除了我没有设置的明显的 -FilePath 错误之外它还有效。您似乎得到了基本的“命令不存在”异常。要检查您的版本号,请使用get-hostcmdlet。运行get-host | select version,如果它输出 1.0 到控制台,你应该去这里获取 2.0 版本。

于 2012-07-23T19:54:18.563 回答